2 ** $Id: lcode.c,v 2.62.1.1 2013/04/12 18:48:47 roberto Exp $
3 ** Code generator for Lua
4 ** See Copyright Notice in lua.h
10 #if defined(HAVE_IMPLICIT_FALLTHROUGH)
11 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
14 #include <sys/lua/lua.h>
30 #define hasjumps(e) ((e)->t != (e)->f)
33 static int isnumeral(expdesc
*e
) {
34 return (e
->k
== VKNUM
&& e
->t
== NO_JUMP
&& e
->f
== NO_JUMP
);
38 void luaK_nil (FuncState
*fs
, int from
, int n
) {
39 Instruction
*previous
;
40 int l
= from
+ n
- 1; /* last register to set nil */
41 if (fs
->pc
> fs
->lasttarget
) { /* no jumps to current position? */
42 previous
= &fs
->f
->code
[fs
->pc
-1];
43 if (GET_OPCODE(*previous
) == OP_LOADNIL
) {
44 int pfrom
= GETARG_A(*previous
);
45 int pl
= pfrom
+ GETARG_B(*previous
);
46 if ((pfrom
<= from
&& from
<= pl
+ 1) ||
47 (from
<= pfrom
&& pfrom
<= l
+ 1)) { /* can connect both? */
48 if (pfrom
< from
) from
= pfrom
; /* from = min(from, pfrom) */
49 if (pl
> l
) l
= pl
; /* l = max(l, pl) */
50 SETARG_A(*previous
, from
);
51 SETARG_B(*previous
, l
- from
);
54 } /* else go through */
56 luaK_codeABC(fs
, OP_LOADNIL
, from
, n
- 1, 0); /* else no optimization */
60 int luaK_jump (FuncState
*fs
) {
61 int jpc
= fs
->jpc
; /* save list of jumps to here */
64 j
= luaK_codeAsBx(fs
, OP_JMP
, 0, NO_JUMP
);
65 luaK_concat(fs
, &j
, jpc
); /* keep them on hold */
70 void luaK_ret (FuncState
*fs
, int first
, int nret
) {
71 luaK_codeABC(fs
, OP_RETURN
, first
, nret
+1, 0);
75 static int condjump (FuncState
*fs
, OpCode op
, int A
, int B
, int C
) {
76 luaK_codeABC(fs
, op
, A
, B
, C
);
81 static void fixjump (FuncState
*fs
, int pc
, int dest
) {
82 Instruction
*jmp
= &fs
->f
->code
[pc
];
83 int offset
= dest
-(pc
+1);
84 lua_assert(dest
!= NO_JUMP
);
85 if (abs(offset
) > MAXARG_sBx
)
86 luaX_syntaxerror(fs
->ls
, "control structure too long");
87 SETARG_sBx(*jmp
, offset
);
92 ** returns current `pc' and marks it as a jump target (to avoid wrong
93 ** optimizations with consecutive instructions not in the same basic block).
95 int luaK_getlabel (FuncState
*fs
) {
96 fs
->lasttarget
= fs
->pc
;
101 static int getjump (FuncState
*fs
, int pc
) {
102 int offset
= GETARG_sBx(fs
->f
->code
[pc
]);
103 if (offset
== NO_JUMP
) /* point to itself represents end of list */
104 return NO_JUMP
; /* end of list */
106 return (pc
+1)+offset
; /* turn offset into absolute position */
110 static Instruction
*getjumpcontrol (FuncState
*fs
, int pc
) {
111 Instruction
*pi
= &fs
->f
->code
[pc
];
112 if (pc
>= 1 && testTMode(GET_OPCODE(*(pi
-1))))
120 ** check whether list has any jump that do not produce a value
121 ** (or produce an inverted value)
123 static int need_value (FuncState
*fs
, int list
) {
124 for (; list
!= NO_JUMP
; list
= getjump(fs
, list
)) {
125 Instruction i
= *getjumpcontrol(fs
, list
);
126 if (GET_OPCODE(i
) != OP_TESTSET
) return 1;
128 return 0; /* not found */
132 static int patchtestreg (FuncState
*fs
, int node
, int reg
) {
133 Instruction
*i
= getjumpcontrol(fs
, node
);
134 if (GET_OPCODE(*i
) != OP_TESTSET
)
135 return 0; /* cannot patch other instructions */
136 if (reg
!= NO_REG
&& reg
!= GETARG_B(*i
))
138 else /* no register to put value or register already has the value */
139 *i
= CREATE_ABC(OP_TEST
, GETARG_B(*i
), 0, GETARG_C(*i
));
145 static void removevalues (FuncState
*fs
, int list
) {
146 for (; list
!= NO_JUMP
; list
= getjump(fs
, list
))
147 patchtestreg(fs
, list
, NO_REG
);
151 static void patchlistaux (FuncState
*fs
, int list
, int vtarget
, int reg
,
153 while (list
!= NO_JUMP
) {
154 int next
= getjump(fs
, list
);
155 if (patchtestreg(fs
, list
, reg
))
156 fixjump(fs
, list
, vtarget
);
158 fixjump(fs
, list
, dtarget
); /* jump to default target */
164 static void dischargejpc (FuncState
*fs
) {
165 patchlistaux(fs
, fs
->jpc
, fs
->pc
, NO_REG
, fs
->pc
);
170 void luaK_patchlist (FuncState
*fs
, int list
, int target
) {
171 if (target
== fs
->pc
)
172 luaK_patchtohere(fs
, list
);
174 lua_assert(target
< fs
->pc
);
175 patchlistaux(fs
, list
, target
, NO_REG
, target
);
180 LUAI_FUNC
void luaK_patchclose (FuncState
*fs
, int list
, int level
) {
181 level
++; /* argument is +1 to reserve 0 as non-op */
182 while (list
!= NO_JUMP
) {
183 int next
= getjump(fs
, list
);
184 lua_assert(GET_OPCODE(fs
->f
->code
[list
]) == OP_JMP
&&
185 (GETARG_A(fs
->f
->code
[list
]) == 0 ||
186 GETARG_A(fs
->f
->code
[list
]) >= level
));
187 SETARG_A(fs
->f
->code
[list
], level
);
193 void luaK_patchtohere (FuncState
*fs
, int list
) {
195 luaK_concat(fs
, &fs
->jpc
, list
);
199 void luaK_concat (FuncState
*fs
, int *l1
, int l2
) {
200 if (l2
== NO_JUMP
) return;
201 else if (*l1
== NO_JUMP
)
206 while ((next
= getjump(fs
, list
)) != NO_JUMP
) /* find last element */
208 fixjump(fs
, list
, l2
);
213 static int luaK_code (FuncState
*fs
, Instruction i
) {
215 dischargejpc(fs
); /* `pc' will change */
216 /* put new instruction in code array */
217 luaM_growvector(fs
->ls
->L
, f
->code
, fs
->pc
, f
->sizecode
, Instruction
,
220 /* save corresponding line information */
221 luaM_growvector(fs
->ls
->L
, f
->lineinfo
, fs
->pc
, f
->sizelineinfo
, int,
223 f
->lineinfo
[fs
->pc
] = fs
->ls
->lastline
;
228 int luaK_codeABC (FuncState
*fs
, OpCode o
, int a
, int b
, int c
) {
229 lua_assert(getOpMode(o
) == iABC
);
230 lua_assert(getBMode(o
) != OpArgN
|| b
== 0);
231 lua_assert(getCMode(o
) != OpArgN
|| c
== 0);
232 lua_assert(a
<= MAXARG_A
&& b
<= MAXARG_B
&& c
<= MAXARG_C
);
233 return luaK_code(fs
, CREATE_ABC(o
, a
, b
, c
));
237 int luaK_codeABx (FuncState
*fs
, OpCode o
, int a
, unsigned int bc
) {
238 lua_assert(getOpMode(o
) == iABx
|| getOpMode(o
) == iAsBx
);
239 lua_assert(getCMode(o
) == OpArgN
);
240 lua_assert(a
<= MAXARG_A
&& bc
<= MAXARG_Bx
);
241 return luaK_code(fs
, CREATE_ABx(o
, a
, bc
));
245 static int codeextraarg (FuncState
*fs
, int a
) {
246 lua_assert(a
<= MAXARG_Ax
);
247 return luaK_code(fs
, CREATE_Ax(OP_EXTRAARG
, a
));
251 int luaK_codek (FuncState
*fs
, int reg
, int k
) {
253 return luaK_codeABx(fs
, OP_LOADK
, reg
, k
);
255 int p
= luaK_codeABx(fs
, OP_LOADKX
, reg
, 0);
262 void luaK_checkstack (FuncState
*fs
, int n
) {
263 int newstack
= fs
->freereg
+ n
;
264 if (newstack
> fs
->f
->maxstacksize
) {
265 if (newstack
>= MAXSTACK
)
266 luaX_syntaxerror(fs
->ls
, "function or expression too complex");
267 fs
->f
->maxstacksize
= cast_byte(newstack
);
272 void luaK_reserveregs (FuncState
*fs
, int n
) {
273 luaK_checkstack(fs
, n
);
278 static void freereg (FuncState
*fs
, int reg
) {
279 if (!ISK(reg
) && reg
>= fs
->nactvar
) {
281 lua_assert(reg
== fs
->freereg
);
286 static void freeexp (FuncState
*fs
, expdesc
*e
) {
287 if (e
->k
== VNONRELOC
)
288 freereg(fs
, e
->u
.info
);
292 static int addk (FuncState
*fs
, TValue
*key
, TValue
*v
) {
293 lua_State
*L
= fs
->ls
->L
;
294 TValue
*idx
= luaH_set(L
, fs
->h
, key
);
297 if (ttisnumber(idx
)) {
298 lua_Number n
= nvalue(idx
);
299 lua_number2int(k
, n
);
300 if (luaV_rawequalobj(&f
->k
[k
], v
))
302 /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");
303 go through and create a new entry for this value */
305 /* constant not found; create a new entry */
308 /* numerical value does not need GC barrier;
309 table has no metatable, so it does not need to invalidate cache */
310 setnvalue(idx
, cast_num(k
));
311 luaM_growvector(L
, f
->k
, k
, f
->sizek
, TValue
, MAXARG_Ax
, "constants");
312 while (oldsize
< f
->sizek
) setnilvalue(&f
->k
[oldsize
++]);
313 setobj(L
, &f
->k
[k
], v
);
315 luaC_barrier(L
, f
, v
);
320 int luaK_stringK (FuncState
*fs
, TString
*s
) {
322 setsvalue(fs
->ls
->L
, &o
, s
);
323 return addk(fs
, &o
, &o
);
327 int luaK_numberK (FuncState
*fs
, lua_Number r
) {
329 lua_State
*L
= fs
->ls
->L
;
332 if (r
== 0 || luai_numisnan(NULL
, r
)) { /* handle -0 and NaN */
333 /* use raw representation as key to avoid numeric problems */
334 setsvalue(L
, L
->top
++, luaS_newlstr(L
, (char *)&r
, sizeof(r
)));
335 n
= addk(fs
, L
->top
- 1, &o
);
339 n
= addk(fs
, &o
, &o
); /* regular case */
344 static int boolK (FuncState
*fs
, int b
) {
347 return addk(fs
, &o
, &o
);
351 static int nilK (FuncState
*fs
) {
354 /* cannot use nil as key; instead use table itself to represent nil */
355 sethvalue(fs
->ls
->L
, &k
, fs
->h
);
356 return addk(fs
, &k
, &v
);
360 void luaK_setreturns (FuncState
*fs
, expdesc
*e
, int nresults
) {
361 if (e
->k
== VCALL
) { /* expression is an open function call? */
362 SETARG_C(getcode(fs
, e
), nresults
+1);
364 else if (e
->k
== VVARARG
) {
365 SETARG_B(getcode(fs
, e
), nresults
+1);
366 SETARG_A(getcode(fs
, e
), fs
->freereg
);
367 luaK_reserveregs(fs
, 1);
372 void luaK_setoneret (FuncState
*fs
, expdesc
*e
) {
373 if (e
->k
== VCALL
) { /* expression is an open function call? */
375 e
->u
.info
= GETARG_A(getcode(fs
, e
));
377 else if (e
->k
== VVARARG
) {
378 SETARG_B(getcode(fs
, e
), 2);
379 e
->k
= VRELOCABLE
; /* can relocate its simple result */
384 void luaK_dischargevars (FuncState
*fs
, expdesc
*e
) {
391 e
->u
.info
= luaK_codeABC(fs
, OP_GETUPVAL
, 0, e
->u
.info
, 0);
396 OpCode op
= OP_GETTABUP
; /* assume 't' is in an upvalue */
397 freereg(fs
, e
->u
.ind
.idx
);
398 if (e
->u
.ind
.vt
== VLOCAL
) { /* 't' is in a register? */
399 freereg(fs
, e
->u
.ind
.t
);
402 e
->u
.info
= luaK_codeABC(fs
, op
, 0, e
->u
.ind
.t
, e
->u
.ind
.idx
);
408 luaK_setoneret(fs
, e
);
411 default: break; /* there is one value available (somewhere) */
416 static int code_label (FuncState
*fs
, int A
, int b
, int jump
) {
417 luaK_getlabel(fs
); /* those instructions may be jump targets */
418 return luaK_codeABC(fs
, OP_LOADBOOL
, A
, b
, jump
);
422 static void discharge2reg (FuncState
*fs
, expdesc
*e
, int reg
) {
423 luaK_dischargevars(fs
, e
);
426 luaK_nil(fs
, reg
, 1);
429 case VFALSE
: case VTRUE
: {
430 luaK_codeABC(fs
, OP_LOADBOOL
, reg
, e
->k
== VTRUE
, 0);
434 luaK_codek(fs
, reg
, e
->u
.info
);
438 luaK_codek(fs
, reg
, luaK_numberK(fs
, e
->u
.nval
));
442 Instruction
*pc
= &getcode(fs
, e
);
447 if (reg
!= e
->u
.info
)
448 luaK_codeABC(fs
, OP_MOVE
, reg
, e
->u
.info
, 0);
452 lua_assert(e
->k
== VVOID
|| e
->k
== VJMP
);
453 return; /* nothing to do... */
461 static void discharge2anyreg (FuncState
*fs
, expdesc
*e
) {
462 if (e
->k
!= VNONRELOC
) {
463 luaK_reserveregs(fs
, 1);
464 discharge2reg(fs
, e
, fs
->freereg
-1);
469 static void exp2reg (FuncState
*fs
, expdesc
*e
, int reg
) {
470 discharge2reg(fs
, e
, reg
);
472 luaK_concat(fs
, &e
->t
, e
->u
.info
); /* put this jump in `t' list */
474 int final
; /* position after whole expression */
475 int p_f
= NO_JUMP
; /* position of an eventual LOAD false */
476 int p_t
= NO_JUMP
; /* position of an eventual LOAD true */
477 if (need_value(fs
, e
->t
) || need_value(fs
, e
->f
)) {
478 int fj
= (e
->k
== VJMP
) ? NO_JUMP
: luaK_jump(fs
);
479 p_f
= code_label(fs
, reg
, 0, 1);
480 p_t
= code_label(fs
, reg
, 1, 0);
481 luaK_patchtohere(fs
, fj
);
483 final
= luaK_getlabel(fs
);
484 patchlistaux(fs
, e
->f
, final
, reg
, p_f
);
485 patchlistaux(fs
, e
->t
, final
, reg
, p_t
);
487 e
->f
= e
->t
= NO_JUMP
;
493 void luaK_exp2nextreg (FuncState
*fs
, expdesc
*e
) {
494 luaK_dischargevars(fs
, e
);
496 luaK_reserveregs(fs
, 1);
497 exp2reg(fs
, e
, fs
->freereg
- 1);
501 int luaK_exp2anyreg (FuncState
*fs
, expdesc
*e
) {
502 luaK_dischargevars(fs
, e
);
503 if (e
->k
== VNONRELOC
) {
504 if (!hasjumps(e
)) return e
->u
.info
; /* exp is already in a register */
505 if (e
->u
.info
>= fs
->nactvar
) { /* reg. is not a local? */
506 exp2reg(fs
, e
, e
->u
.info
); /* put value on it */
510 luaK_exp2nextreg(fs
, e
); /* default */
515 void luaK_exp2anyregup (FuncState
*fs
, expdesc
*e
) {
516 if (e
->k
!= VUPVAL
|| hasjumps(e
))
517 luaK_exp2anyreg(fs
, e
);
521 void luaK_exp2val (FuncState
*fs
, expdesc
*e
) {
523 luaK_exp2anyreg(fs
, e
);
525 luaK_dischargevars(fs
, e
);
529 int luaK_exp2RK (FuncState
*fs
, expdesc
*e
) {
535 if (fs
->nk
<= MAXINDEXRK
) { /* constant fits in RK operand? */
536 e
->u
.info
= (e
->k
== VNIL
) ? nilK(fs
) : boolK(fs
, (e
->k
== VTRUE
));
538 return RKASK(e
->u
.info
);
543 e
->u
.info
= luaK_numberK(fs
, e
->u
.nval
);
548 if (e
->u
.info
<= MAXINDEXRK
) /* constant fits in argC? */
549 return RKASK(e
->u
.info
);
554 /* not a constant in the right range: put it in a register */
555 return luaK_exp2anyreg(fs
, e
);
559 void luaK_storevar (FuncState
*fs
, expdesc
*var
, expdesc
*ex
) {
563 exp2reg(fs
, ex
, var
->u
.info
);
567 int e
= luaK_exp2anyreg(fs
, ex
);
568 luaK_codeABC(fs
, OP_SETUPVAL
, e
, var
->u
.info
, 0);
572 OpCode op
= (var
->u
.ind
.vt
== VLOCAL
) ? OP_SETTABLE
: OP_SETTABUP
;
573 int e
= luaK_exp2RK(fs
, ex
);
574 luaK_codeABC(fs
, op
, var
->u
.ind
.t
, var
->u
.ind
.idx
, e
);
578 lua_assert(0); /* invalid var kind to store */
586 void luaK_self (FuncState
*fs
, expdesc
*e
, expdesc
*key
) {
588 luaK_exp2anyreg(fs
, e
);
589 ereg
= e
->u
.info
; /* register where 'e' was placed */
591 e
->u
.info
= fs
->freereg
; /* base register for op_self */
593 luaK_reserveregs(fs
, 2); /* function and 'self' produced by op_self */
594 luaK_codeABC(fs
, OP_SELF
, e
->u
.info
, ereg
, luaK_exp2RK(fs
, key
));
599 static void invertjump (FuncState
*fs
, expdesc
*e
) {
600 Instruction
*pc
= getjumpcontrol(fs
, e
->u
.info
);
601 lua_assert(testTMode(GET_OPCODE(*pc
)) && GET_OPCODE(*pc
) != OP_TESTSET
&&
602 GET_OPCODE(*pc
) != OP_TEST
);
603 SETARG_A(*pc
, !(GETARG_A(*pc
)));
607 static int jumponcond (FuncState
*fs
, expdesc
*e
, int cond
) {
608 if (e
->k
== VRELOCABLE
) {
609 Instruction ie
= getcode(fs
, e
);
610 if (GET_OPCODE(ie
) == OP_NOT
) {
611 fs
->pc
--; /* remove previous OP_NOT */
612 return condjump(fs
, OP_TEST
, GETARG_B(ie
), 0, !cond
);
614 /* else go through */
616 discharge2anyreg(fs
, e
);
618 return condjump(fs
, OP_TESTSET
, NO_REG
, e
->u
.info
, cond
);
622 void luaK_goiftrue (FuncState
*fs
, expdesc
*e
) {
623 int pc
; /* pc of last jump */
624 luaK_dischargevars(fs
, e
);
631 case VK
: case VKNUM
: case VTRUE
: {
632 pc
= NO_JUMP
; /* always true; do nothing */
636 pc
= jumponcond(fs
, e
, 0);
640 luaK_concat(fs
, &e
->f
, pc
); /* insert last jump in `f' list */
641 luaK_patchtohere(fs
, e
->t
);
646 void luaK_goiffalse (FuncState
*fs
, expdesc
*e
) {
647 int pc
; /* pc of last jump */
648 luaK_dischargevars(fs
, e
);
654 case VNIL
: case VFALSE
: {
655 pc
= NO_JUMP
; /* always false; do nothing */
659 pc
= jumponcond(fs
, e
, 1);
663 luaK_concat(fs
, &e
->t
, pc
); /* insert last jump in `t' list */
664 luaK_patchtohere(fs
, e
->f
);
669 static void codenot (FuncState
*fs
, expdesc
*e
) {
670 luaK_dischargevars(fs
, e
);
672 case VNIL
: case VFALSE
: {
676 case VK
: case VKNUM
: case VTRUE
: {
686 discharge2anyreg(fs
, e
);
688 e
->u
.info
= luaK_codeABC(fs
, OP_NOT
, 0, e
->u
.info
, 0);
693 lua_assert(0); /* cannot happen */
697 /* interchange true and false lists */
698 { int temp
= e
->f
; e
->f
= e
->t
; e
->t
= temp
; }
699 removevalues(fs
, e
->f
);
700 removevalues(fs
, e
->t
);
704 void luaK_indexed (FuncState
*fs
, expdesc
*t
, expdesc
*k
) {
705 lua_assert(!hasjumps(t
));
706 t
->u
.ind
.t
= t
->u
.info
;
707 t
->u
.ind
.idx
= luaK_exp2RK(fs
, k
);
708 t
->u
.ind
.vt
= (t
->k
== VUPVAL
) ? VUPVAL
709 : check_exp(vkisinreg(t
->k
), VLOCAL
);
714 static int constfolding (OpCode op
, expdesc
*e1
, expdesc
*e2
) {
716 if (!isnumeral(e1
) || !isnumeral(e2
)) return 0;
717 if ((op
== OP_DIV
|| op
== OP_MOD
) && e2
->u
.nval
== 0)
718 return 0; /* do not attempt to divide by 0 */
720 * Patched: check for MIN_INT / -1
722 if (op
== OP_DIV
&& e1
->u
.nval
== INT64_MIN
&& e2
->u
.nval
== -1)
724 r
= luaO_arith(op
- OP_ADD
+ LUA_OPADD
, e1
->u
.nval
, e2
->u
.nval
);
730 static void codearith (FuncState
*fs
, OpCode op
,
731 expdesc
*e1
, expdesc
*e2
, int line
) {
732 if (constfolding(op
, e1
, e2
))
735 int o2
= (op
!= OP_UNM
&& op
!= OP_LEN
) ? luaK_exp2RK(fs
, e2
) : 0;
736 int o1
= luaK_exp2RK(fs
, e1
);
745 e1
->u
.info
= luaK_codeABC(fs
, op
, 0, o1
, o2
);
747 luaK_fixline(fs
, line
);
752 static void codecomp (FuncState
*fs
, OpCode op
, int cond
, expdesc
*e1
,
754 int o1
= luaK_exp2RK(fs
, e1
);
755 int o2
= luaK_exp2RK(fs
, e2
);
758 if (cond
== 0 && op
!= OP_EQ
) {
759 int temp
; /* exchange args to replace by `<' or `<=' */
760 temp
= o1
; o1
= o2
; o2
= temp
; /* o1 <==> o2 */
763 e1
->u
.info
= condjump(fs
, op
, cond
, o1
, o2
);
768 void luaK_prefix (FuncState
*fs
, UnOpr op
, expdesc
*e
, int line
) {
770 e2
.t
= e2
.f
= NO_JUMP
; e2
.k
= VKNUM
; e2
.u
.nval
= 0;
773 if (isnumeral(e
)) /* minus constant? */
774 e
->u
.nval
= luai_numunm(NULL
, e
->u
.nval
); /* fold it */
776 luaK_exp2anyreg(fs
, e
);
777 codearith(fs
, OP_UNM
, e
, &e2
, line
);
781 case OPR_NOT
: codenot(fs
, e
); break;
783 luaK_exp2anyreg(fs
, e
); /* cannot operate on constants */
784 codearith(fs
, OP_LEN
, e
, &e2
, line
);
787 default: lua_assert(0);
792 void luaK_infix (FuncState
*fs
, BinOpr op
, expdesc
*v
) {
795 luaK_goiftrue(fs
, v
);
799 luaK_goiffalse(fs
, v
);
803 luaK_exp2nextreg(fs
, v
); /* operand must be on the `stack' */
806 case OPR_ADD
: case OPR_SUB
: case OPR_MUL
: case OPR_DIV
:
807 case OPR_MOD
: case OPR_POW
: {
808 if (!isnumeral(v
)) luaK_exp2RK(fs
, v
);
819 void luaK_posfix (FuncState
*fs
, BinOpr op
,
820 expdesc
*e1
, expdesc
*e2
, int line
) {
823 lua_assert(e1
->t
== NO_JUMP
); /* list must be closed */
824 luaK_dischargevars(fs
, e2
);
825 luaK_concat(fs
, &e2
->f
, e1
->f
);
830 lua_assert(e1
->f
== NO_JUMP
); /* list must be closed */
831 luaK_dischargevars(fs
, e2
);
832 luaK_concat(fs
, &e2
->t
, e1
->t
);
837 luaK_exp2val(fs
, e2
);
838 if (e2
->k
== VRELOCABLE
&& GET_OPCODE(getcode(fs
, e2
)) == OP_CONCAT
) {
839 lua_assert(e1
->u
.info
== GETARG_B(getcode(fs
, e2
))-1);
841 SETARG_B(getcode(fs
, e2
), e1
->u
.info
);
842 e1
->k
= VRELOCABLE
; e1
->u
.info
= e2
->u
.info
;
845 luaK_exp2nextreg(fs
, e2
); /* operand must be on the 'stack' */
846 codearith(fs
, OP_CONCAT
, e1
, e2
, line
);
850 case OPR_ADD
: case OPR_SUB
: case OPR_MUL
: case OPR_DIV
:
851 case OPR_MOD
: case OPR_POW
: {
852 codearith(fs
, cast(OpCode
, op
- OPR_ADD
+ OP_ADD
), e1
, e2
, line
);
855 case OPR_EQ
: case OPR_LT
: case OPR_LE
: {
856 codecomp(fs
, cast(OpCode
, op
- OPR_EQ
+ OP_EQ
), 1, e1
, e2
);
859 case OPR_NE
: case OPR_GT
: case OPR_GE
: {
860 codecomp(fs
, cast(OpCode
, op
- OPR_NE
+ OP_EQ
), 0, e1
, e2
);
863 default: lua_assert(0);
868 void luaK_fixline (FuncState
*fs
, int line
) {
869 fs
->f
->lineinfo
[fs
->pc
- 1] = line
;
873 void luaK_setlist (FuncState
*fs
, int base
, int nelems
, int tostore
) {
874 int c
= (nelems
- 1)/LFIELDS_PER_FLUSH
+ 1;
875 int b
= (tostore
== LUA_MULTRET
) ? 0 : tostore
;
876 lua_assert(tostore
!= 0);
878 luaK_codeABC(fs
, OP_SETLIST
, base
, b
, c
);
879 else if (c
<= MAXARG_Ax
) {
880 luaK_codeABC(fs
, OP_SETLIST
, base
, b
, 0);
884 luaX_syntaxerror(fs
->ls
, "constructor too long");
885 fs
->freereg
= base
+ 1; /* free registers with list values */