]>
git.proxmox.com Git - mirror_zfs.git/blob - module/lua/lcode.c
3 ** $Id: lcode.c,v 2.62.1.1 2013/04/12 18:48:47 roberto Exp $
4 ** Code generator for Lua
5 ** See Copyright Notice in lua.h
11 #include <sys/lua/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 int l
= from
+ n
- 1; /* last register to set nil */
38 if (fs
->pc
> fs
->lasttarget
) { /* no jumps to current position? */
39 previous
= &fs
->f
->code
[fs
->pc
-1];
40 if (GET_OPCODE(*previous
) == OP_LOADNIL
) {
41 int pfrom
= GETARG_A(*previous
);
42 int pl
= pfrom
+ GETARG_B(*previous
);
43 if ((pfrom
<= from
&& from
<= pl
+ 1) ||
44 (from
<= pfrom
&& pfrom
<= l
+ 1)) { /* can connect both? */
45 if (pfrom
< from
) from
= pfrom
; /* from = min(from, pfrom) */
46 if (pl
> l
) l
= pl
; /* l = max(l, pl) */
47 SETARG_A(*previous
, from
);
48 SETARG_B(*previous
, l
- from
);
51 } /* else go through */
53 luaK_codeABC(fs
, OP_LOADNIL
, from
, n
- 1, 0); /* else no optimization */
57 int luaK_jump (FuncState
*fs
) {
58 int jpc
= fs
->jpc
; /* save list of jumps to here */
61 j
= luaK_codeAsBx(fs
, OP_JMP
, 0, NO_JUMP
);
62 luaK_concat(fs
, &j
, jpc
); /* keep them on hold */
67 void luaK_ret (FuncState
*fs
, int first
, int nret
) {
68 luaK_codeABC(fs
, OP_RETURN
, first
, nret
+1, 0);
72 static int condjump (FuncState
*fs
, OpCode op
, int A
, int B
, int C
) {
73 luaK_codeABC(fs
, op
, A
, B
, C
);
78 static void fixjump (FuncState
*fs
, int pc
, int dest
) {
79 Instruction
*jmp
= &fs
->f
->code
[pc
];
80 int offset
= dest
-(pc
+1);
81 lua_assert(dest
!= NO_JUMP
);
82 if (abs(offset
) > MAXARG_sBx
)
83 luaX_syntaxerror(fs
->ls
, "control structure too long");
84 SETARG_sBx(*jmp
, offset
);
89 ** returns current `pc' and marks it as a jump target (to avoid wrong
90 ** optimizations with consecutive instructions not in the same basic block).
92 int luaK_getlabel (FuncState
*fs
) {
93 fs
->lasttarget
= fs
->pc
;
98 static int getjump (FuncState
*fs
, int pc
) {
99 int offset
= GETARG_sBx(fs
->f
->code
[pc
]);
100 if (offset
== NO_JUMP
) /* point to itself represents end of list */
101 return NO_JUMP
; /* end of list */
103 return (pc
+1)+offset
; /* turn offset into absolute position */
107 static Instruction
*getjumpcontrol (FuncState
*fs
, int pc
) {
108 Instruction
*pi
= &fs
->f
->code
[pc
];
109 if (pc
>= 1 && testTMode(GET_OPCODE(*(pi
-1))))
117 ** check whether list has any jump that do not produce a value
118 ** (or produce an inverted value)
120 static int need_value (FuncState
*fs
, int list
) {
121 for (; list
!= NO_JUMP
; list
= getjump(fs
, list
)) {
122 Instruction i
= *getjumpcontrol(fs
, list
);
123 if (GET_OPCODE(i
) != OP_TESTSET
) return 1;
125 return 0; /* not found */
129 static int patchtestreg (FuncState
*fs
, int node
, int reg
) {
130 Instruction
*i
= getjumpcontrol(fs
, node
);
131 if (GET_OPCODE(*i
) != OP_TESTSET
)
132 return 0; /* cannot patch other instructions */
133 if (reg
!= NO_REG
&& reg
!= GETARG_B(*i
))
135 else /* no register to put value or register already has the value */
136 *i
= CREATE_ABC(OP_TEST
, GETARG_B(*i
), 0, GETARG_C(*i
));
142 static void removevalues (FuncState
*fs
, int list
) {
143 for (; list
!= NO_JUMP
; list
= getjump(fs
, list
))
144 patchtestreg(fs
, list
, NO_REG
);
148 static void patchlistaux (FuncState
*fs
, int list
, int vtarget
, int reg
,
150 while (list
!= NO_JUMP
) {
151 int next
= getjump(fs
, list
);
152 if (patchtestreg(fs
, list
, reg
))
153 fixjump(fs
, list
, vtarget
);
155 fixjump(fs
, list
, dtarget
); /* jump to default target */
161 static void dischargejpc (FuncState
*fs
) {
162 patchlistaux(fs
, fs
->jpc
, fs
->pc
, NO_REG
, fs
->pc
);
167 void luaK_patchlist (FuncState
*fs
, int list
, int target
) {
168 if (target
== fs
->pc
)
169 luaK_patchtohere(fs
, list
);
171 lua_assert(target
< fs
->pc
);
172 patchlistaux(fs
, list
, target
, NO_REG
, target
);
177 LUAI_FUNC
void luaK_patchclose (FuncState
*fs
, int list
, int level
) {
178 level
++; /* argument is +1 to reserve 0 as non-op */
179 while (list
!= NO_JUMP
) {
180 int next
= getjump(fs
, list
);
181 lua_assert(GET_OPCODE(fs
->f
->code
[list
]) == OP_JMP
&&
182 (GETARG_A(fs
->f
->code
[list
]) == 0 ||
183 GETARG_A(fs
->f
->code
[list
]) >= level
));
184 SETARG_A(fs
->f
->code
[list
], level
);
190 void luaK_patchtohere (FuncState
*fs
, int list
) {
192 luaK_concat(fs
, &fs
->jpc
, list
);
196 void luaK_concat (FuncState
*fs
, int *l1
, int l2
) {
197 if (l2
== NO_JUMP
) return;
198 else if (*l1
== NO_JUMP
)
203 while ((next
= getjump(fs
, list
)) != NO_JUMP
) /* find last element */
205 fixjump(fs
, list
, l2
);
210 static int luaK_code (FuncState
*fs
, Instruction i
) {
212 dischargejpc(fs
); /* `pc' will change */
213 /* put new instruction in code array */
214 luaM_growvector(fs
->ls
->L
, f
->code
, fs
->pc
, f
->sizecode
, Instruction
,
217 /* save corresponding line information */
218 luaM_growvector(fs
->ls
->L
, f
->lineinfo
, fs
->pc
, f
->sizelineinfo
, int,
220 f
->lineinfo
[fs
->pc
] = fs
->ls
->lastline
;
225 int luaK_codeABC (FuncState
*fs
, OpCode o
, int a
, int b
, int c
) {
226 lua_assert(getOpMode(o
) == iABC
);
227 lua_assert(getBMode(o
) != OpArgN
|| b
== 0);
228 lua_assert(getCMode(o
) != OpArgN
|| c
== 0);
229 lua_assert(a
<= MAXARG_A
&& b
<= MAXARG_B
&& c
<= MAXARG_C
);
230 return luaK_code(fs
, CREATE_ABC(o
, a
, b
, c
));
234 int luaK_codeABx (FuncState
*fs
, OpCode o
, int a
, unsigned int bc
) {
235 lua_assert(getOpMode(o
) == iABx
|| getOpMode(o
) == iAsBx
);
236 lua_assert(getCMode(o
) == OpArgN
);
237 lua_assert(a
<= MAXARG_A
&& bc
<= MAXARG_Bx
);
238 return luaK_code(fs
, CREATE_ABx(o
, a
, bc
));
242 static int codeextraarg (FuncState
*fs
, int a
) {
243 lua_assert(a
<= MAXARG_Ax
);
244 return luaK_code(fs
, CREATE_Ax(OP_EXTRAARG
, a
));
248 int luaK_codek (FuncState
*fs
, int reg
, int k
) {
250 return luaK_codeABx(fs
, OP_LOADK
, reg
, k
);
252 int p
= luaK_codeABx(fs
, OP_LOADKX
, reg
, 0);
259 void luaK_checkstack (FuncState
*fs
, int n
) {
260 int newstack
= fs
->freereg
+ n
;
261 if (newstack
> fs
->f
->maxstacksize
) {
262 if (newstack
>= MAXSTACK
)
263 luaX_syntaxerror(fs
->ls
, "function or expression too complex");
264 fs
->f
->maxstacksize
= cast_byte(newstack
);
269 void luaK_reserveregs (FuncState
*fs
, int n
) {
270 luaK_checkstack(fs
, n
);
275 static void freereg (FuncState
*fs
, int reg
) {
276 if (!ISK(reg
) && reg
>= fs
->nactvar
) {
278 lua_assert(reg
== fs
->freereg
);
283 static void freeexp (FuncState
*fs
, expdesc
*e
) {
284 if (e
->k
== VNONRELOC
)
285 freereg(fs
, e
->u
.info
);
289 static int addk (FuncState
*fs
, TValue
*key
, TValue
*v
) {
290 lua_State
*L
= fs
->ls
->L
;
291 TValue
*idx
= luaH_set(L
, fs
->h
, key
);
294 if (ttisnumber(idx
)) {
295 lua_Number n
= nvalue(idx
);
296 lua_number2int(k
, n
);
297 if (luaV_rawequalobj(&f
->k
[k
], v
))
299 /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");
300 go through and create a new entry for this value */
302 /* constant not found; create a new entry */
305 /* numerical value does not need GC barrier;
306 table has no metatable, so it does not need to invalidate cache */
307 setnvalue(idx
, cast_num(k
));
308 luaM_growvector(L
, f
->k
, k
, f
->sizek
, TValue
, MAXARG_Ax
, "constants");
309 while (oldsize
< f
->sizek
) setnilvalue(&f
->k
[oldsize
++]);
310 setobj(L
, &f
->k
[k
], v
);
312 luaC_barrier(L
, f
, v
);
317 int luaK_stringK (FuncState
*fs
, TString
*s
) {
319 setsvalue(fs
->ls
->L
, &o
, s
);
320 return addk(fs
, &o
, &o
);
324 int luaK_numberK (FuncState
*fs
, lua_Number r
) {
326 lua_State
*L
= fs
->ls
->L
;
329 if (r
== 0 || luai_numisnan(NULL
, r
)) { /* handle -0 and NaN */
330 /* use raw representation as key to avoid numeric problems */
331 setsvalue(L
, L
->top
++, luaS_newlstr(L
, (char *)&r
, sizeof(r
)));
332 n
= addk(fs
, L
->top
- 1, &o
);
336 n
= addk(fs
, &o
, &o
); /* regular case */
341 static int boolK (FuncState
*fs
, int b
) {
344 return addk(fs
, &o
, &o
);
348 static int nilK (FuncState
*fs
) {
351 /* cannot use nil as key; instead use table itself to represent nil */
352 sethvalue(fs
->ls
->L
, &k
, fs
->h
);
353 return addk(fs
, &k
, &v
);
357 void luaK_setreturns (FuncState
*fs
, expdesc
*e
, int nresults
) {
358 if (e
->k
== VCALL
) { /* expression is an open function call? */
359 SETARG_C(getcode(fs
, e
), nresults
+1);
361 else if (e
->k
== VVARARG
) {
362 SETARG_B(getcode(fs
, e
), nresults
+1);
363 SETARG_A(getcode(fs
, e
), fs
->freereg
);
364 luaK_reserveregs(fs
, 1);
369 void luaK_setoneret (FuncState
*fs
, expdesc
*e
) {
370 if (e
->k
== VCALL
) { /* expression is an open function call? */
372 e
->u
.info
= GETARG_A(getcode(fs
, e
));
374 else if (e
->k
== VVARARG
) {
375 SETARG_B(getcode(fs
, e
), 2);
376 e
->k
= VRELOCABLE
; /* can relocate its simple result */
381 void luaK_dischargevars (FuncState
*fs
, expdesc
*e
) {
388 e
->u
.info
= luaK_codeABC(fs
, OP_GETUPVAL
, 0, e
->u
.info
, 0);
393 OpCode op
= OP_GETTABUP
; /* assume 't' is in an upvalue */
394 freereg(fs
, e
->u
.ind
.idx
);
395 if (e
->u
.ind
.vt
== VLOCAL
) { /* 't' is in a register? */
396 freereg(fs
, e
->u
.ind
.t
);
399 e
->u
.info
= luaK_codeABC(fs
, op
, 0, e
->u
.ind
.t
, e
->u
.ind
.idx
);
405 luaK_setoneret(fs
, e
);
408 default: break; /* there is one value available (somewhere) */
413 static int code_label (FuncState
*fs
, int A
, int b
, int jump
) {
414 luaK_getlabel(fs
); /* those instructions may be jump targets */
415 return luaK_codeABC(fs
, OP_LOADBOOL
, A
, b
, jump
);
419 static void discharge2reg (FuncState
*fs
, expdesc
*e
, int reg
) {
420 luaK_dischargevars(fs
, e
);
423 luaK_nil(fs
, reg
, 1);
426 case VFALSE
: case VTRUE
: {
427 luaK_codeABC(fs
, OP_LOADBOOL
, reg
, e
->k
== VTRUE
, 0);
431 luaK_codek(fs
, reg
, e
->u
.info
);
435 luaK_codek(fs
, reg
, luaK_numberK(fs
, e
->u
.nval
));
439 Instruction
*pc
= &getcode(fs
, e
);
444 if (reg
!= e
->u
.info
)
445 luaK_codeABC(fs
, OP_MOVE
, reg
, e
->u
.info
, 0);
449 lua_assert(e
->k
== VVOID
|| e
->k
== VJMP
);
450 return; /* nothing to do... */
458 static void discharge2anyreg (FuncState
*fs
, expdesc
*e
) {
459 if (e
->k
!= VNONRELOC
) {
460 luaK_reserveregs(fs
, 1);
461 discharge2reg(fs
, e
, fs
->freereg
-1);
466 static void exp2reg (FuncState
*fs
, expdesc
*e
, int reg
) {
467 discharge2reg(fs
, e
, reg
);
469 luaK_concat(fs
, &e
->t
, e
->u
.info
); /* put this jump in `t' list */
471 int final
; /* position after whole expression */
472 int p_f
= NO_JUMP
; /* position of an eventual LOAD false */
473 int p_t
= NO_JUMP
; /* position of an eventual LOAD true */
474 if (need_value(fs
, e
->t
) || need_value(fs
, e
->f
)) {
475 int fj
= (e
->k
== VJMP
) ? NO_JUMP
: luaK_jump(fs
);
476 p_f
= code_label(fs
, reg
, 0, 1);
477 p_t
= code_label(fs
, reg
, 1, 0);
478 luaK_patchtohere(fs
, fj
);
480 final
= luaK_getlabel(fs
);
481 patchlistaux(fs
, e
->f
, final
, reg
, p_f
);
482 patchlistaux(fs
, e
->t
, final
, reg
, p_t
);
484 e
->f
= e
->t
= NO_JUMP
;
490 void luaK_exp2nextreg (FuncState
*fs
, expdesc
*e
) {
491 luaK_dischargevars(fs
, e
);
493 luaK_reserveregs(fs
, 1);
494 exp2reg(fs
, e
, fs
->freereg
- 1);
498 int luaK_exp2anyreg (FuncState
*fs
, expdesc
*e
) {
499 luaK_dischargevars(fs
, e
);
500 if (e
->k
== VNONRELOC
) {
501 if (!hasjumps(e
)) return e
->u
.info
; /* exp is already in a register */
502 if (e
->u
.info
>= fs
->nactvar
) { /* reg. is not a local? */
503 exp2reg(fs
, e
, e
->u
.info
); /* put value on it */
507 luaK_exp2nextreg(fs
, e
); /* default */
512 void luaK_exp2anyregup (FuncState
*fs
, expdesc
*e
) {
513 if (e
->k
!= VUPVAL
|| hasjumps(e
))
514 luaK_exp2anyreg(fs
, e
);
518 void luaK_exp2val (FuncState
*fs
, expdesc
*e
) {
520 luaK_exp2anyreg(fs
, e
);
522 luaK_dischargevars(fs
, e
);
526 int luaK_exp2RK (FuncState
*fs
, expdesc
*e
) {
532 if (fs
->nk
<= MAXINDEXRK
) { /* constant fits in RK operand? */
533 e
->u
.info
= (e
->k
== VNIL
) ? nilK(fs
) : boolK(fs
, (e
->k
== VTRUE
));
535 return RKASK(e
->u
.info
);
540 e
->u
.info
= luaK_numberK(fs
, e
->u
.nval
);
545 if (e
->u
.info
<= MAXINDEXRK
) /* constant fits in argC? */
546 return RKASK(e
->u
.info
);
551 /* not a constant in the right range: put it in a register */
552 return luaK_exp2anyreg(fs
, e
);
556 void luaK_storevar (FuncState
*fs
, expdesc
*var
, expdesc
*ex
) {
560 exp2reg(fs
, ex
, var
->u
.info
);
564 int e
= luaK_exp2anyreg(fs
, ex
);
565 luaK_codeABC(fs
, OP_SETUPVAL
, e
, var
->u
.info
, 0);
569 OpCode op
= (var
->u
.ind
.vt
== VLOCAL
) ? OP_SETTABLE
: OP_SETTABUP
;
570 int e
= luaK_exp2RK(fs
, ex
);
571 luaK_codeABC(fs
, op
, var
->u
.ind
.t
, var
->u
.ind
.idx
, e
);
575 lua_assert(0); /* invalid var kind to store */
583 void luaK_self (FuncState
*fs
, expdesc
*e
, expdesc
*key
) {
585 luaK_exp2anyreg(fs
, e
);
586 ereg
= e
->u
.info
; /* register where 'e' was placed */
588 e
->u
.info
= fs
->freereg
; /* base register for op_self */
590 luaK_reserveregs(fs
, 2); /* function and 'self' produced by op_self */
591 luaK_codeABC(fs
, OP_SELF
, e
->u
.info
, ereg
, luaK_exp2RK(fs
, key
));
596 static void invertjump (FuncState
*fs
, expdesc
*e
) {
597 Instruction
*pc
= getjumpcontrol(fs
, e
->u
.info
);
598 lua_assert(testTMode(GET_OPCODE(*pc
)) && GET_OPCODE(*pc
) != OP_TESTSET
&&
599 GET_OPCODE(*pc
) != OP_TEST
);
600 SETARG_A(*pc
, !(GETARG_A(*pc
)));
604 static int jumponcond (FuncState
*fs
, expdesc
*e
, int cond
) {
605 if (e
->k
== VRELOCABLE
) {
606 Instruction ie
= getcode(fs
, e
);
607 if (GET_OPCODE(ie
) == OP_NOT
) {
608 fs
->pc
--; /* remove previous OP_NOT */
609 return condjump(fs
, OP_TEST
, GETARG_B(ie
), 0, !cond
);
611 /* else go through */
613 discharge2anyreg(fs
, e
);
615 return condjump(fs
, OP_TESTSET
, NO_REG
, e
->u
.info
, cond
);
619 void luaK_goiftrue (FuncState
*fs
, expdesc
*e
) {
620 int pc
; /* pc of last jump */
621 luaK_dischargevars(fs
, e
);
628 case VK
: case VKNUM
: case VTRUE
: {
629 pc
= NO_JUMP
; /* always true; do nothing */
633 pc
= jumponcond(fs
, e
, 0);
637 luaK_concat(fs
, &e
->f
, pc
); /* insert last jump in `f' list */
638 luaK_patchtohere(fs
, e
->t
);
643 void luaK_goiffalse (FuncState
*fs
, expdesc
*e
) {
644 int pc
; /* pc of last jump */
645 luaK_dischargevars(fs
, e
);
651 case VNIL
: case VFALSE
: {
652 pc
= NO_JUMP
; /* always false; do nothing */
656 pc
= jumponcond(fs
, e
, 1);
660 luaK_concat(fs
, &e
->t
, pc
); /* insert last jump in `t' list */
661 luaK_patchtohere(fs
, e
->f
);
666 static void codenot (FuncState
*fs
, expdesc
*e
) {
667 luaK_dischargevars(fs
, e
);
669 case VNIL
: case VFALSE
: {
673 case VK
: case VKNUM
: case VTRUE
: {
683 discharge2anyreg(fs
, e
);
685 e
->u
.info
= luaK_codeABC(fs
, OP_NOT
, 0, e
->u
.info
, 0);
690 lua_assert(0); /* cannot happen */
694 /* interchange true and false lists */
695 { int temp
= e
->f
; e
->f
= e
->t
; e
->t
= temp
; }
696 removevalues(fs
, e
->f
);
697 removevalues(fs
, e
->t
);
701 void luaK_indexed (FuncState
*fs
, expdesc
*t
, expdesc
*k
) {
702 lua_assert(!hasjumps(t
));
703 t
->u
.ind
.t
= t
->u
.info
;
704 t
->u
.ind
.idx
= luaK_exp2RK(fs
, k
);
705 t
->u
.ind
.vt
= (t
->k
== VUPVAL
) ? VUPVAL
706 : check_exp(vkisinreg(t
->k
), VLOCAL
);
711 static int constfolding (OpCode op
, expdesc
*e1
, expdesc
*e2
) {
713 if (!isnumeral(e1
) || !isnumeral(e2
)) return 0;
714 if ((op
== OP_DIV
|| op
== OP_MOD
) && e2
->u
.nval
== 0)
715 return 0; /* do not attempt to divide by 0 */
717 * Patched: check for MIN_INT / -1
719 if (op
== OP_DIV
&& e1
->u
.nval
== INT64_MIN
&& e2
->u
.nval
== -1)
721 r
= luaO_arith(op
- OP_ADD
+ LUA_OPADD
, e1
->u
.nval
, e2
->u
.nval
);
727 static void codearith (FuncState
*fs
, OpCode op
,
728 expdesc
*e1
, expdesc
*e2
, int line
) {
729 if (constfolding(op
, e1
, e2
))
732 int o2
= (op
!= OP_UNM
&& op
!= OP_LEN
) ? luaK_exp2RK(fs
, e2
) : 0;
733 int o1
= luaK_exp2RK(fs
, e1
);
742 e1
->u
.info
= luaK_codeABC(fs
, op
, 0, o1
, o2
);
744 luaK_fixline(fs
, line
);
749 static void codecomp (FuncState
*fs
, OpCode op
, int cond
, expdesc
*e1
,
751 int o1
= luaK_exp2RK(fs
, e1
);
752 int o2
= luaK_exp2RK(fs
, e2
);
755 if (cond
== 0 && op
!= OP_EQ
) {
756 int temp
; /* exchange args to replace by `<' or `<=' */
757 temp
= o1
; o1
= o2
; o2
= temp
; /* o1 <==> o2 */
760 e1
->u
.info
= condjump(fs
, op
, cond
, o1
, o2
);
765 void luaK_prefix (FuncState
*fs
, UnOpr op
, expdesc
*e
, int line
) {
767 e2
.t
= e2
.f
= NO_JUMP
; e2
.k
= VKNUM
; e2
.u
.nval
= 0;
770 if (isnumeral(e
)) /* minus constant? */
771 e
->u
.nval
= luai_numunm(NULL
, e
->u
.nval
); /* fold it */
773 luaK_exp2anyreg(fs
, e
);
774 codearith(fs
, OP_UNM
, e
, &e2
, line
);
778 case OPR_NOT
: codenot(fs
, e
); break;
780 luaK_exp2anyreg(fs
, e
); /* cannot operate on constants */
781 codearith(fs
, OP_LEN
, e
, &e2
, line
);
784 default: lua_assert(0);
789 void luaK_infix (FuncState
*fs
, BinOpr op
, expdesc
*v
) {
792 luaK_goiftrue(fs
, v
);
796 luaK_goiffalse(fs
, v
);
800 luaK_exp2nextreg(fs
, v
); /* operand must be on the `stack' */
803 case OPR_ADD
: case OPR_SUB
: case OPR_MUL
: case OPR_DIV
:
804 case OPR_MOD
: case OPR_POW
: {
805 if (!isnumeral(v
)) luaK_exp2RK(fs
, v
);
816 void luaK_posfix (FuncState
*fs
, BinOpr op
,
817 expdesc
*e1
, expdesc
*e2
, int line
) {
820 lua_assert(e1
->t
== NO_JUMP
); /* list must be closed */
821 luaK_dischargevars(fs
, e2
);
822 luaK_concat(fs
, &e2
->f
, e1
->f
);
827 lua_assert(e1
->f
== NO_JUMP
); /* list must be closed */
828 luaK_dischargevars(fs
, e2
);
829 luaK_concat(fs
, &e2
->t
, e1
->t
);
834 luaK_exp2val(fs
, e2
);
835 if (e2
->k
== VRELOCABLE
&& GET_OPCODE(getcode(fs
, e2
)) == OP_CONCAT
) {
836 lua_assert(e1
->u
.info
== GETARG_B(getcode(fs
, e2
))-1);
838 SETARG_B(getcode(fs
, e2
), e1
->u
.info
);
839 e1
->k
= VRELOCABLE
; e1
->u
.info
= e2
->u
.info
;
842 luaK_exp2nextreg(fs
, e2
); /* operand must be on the 'stack' */
843 codearith(fs
, OP_CONCAT
, e1
, e2
, line
);
847 case OPR_ADD
: case OPR_SUB
: case OPR_MUL
: case OPR_DIV
:
848 case OPR_MOD
: case OPR_POW
: {
849 codearith(fs
, cast(OpCode
, op
- OPR_ADD
+ OP_ADD
), e1
, e2
, line
);
852 case OPR_EQ
: case OPR_LT
: case OPR_LE
: {
853 codecomp(fs
, cast(OpCode
, op
- OPR_EQ
+ OP_EQ
), 1, e1
, e2
);
856 case OPR_NE
: case OPR_GT
: case OPR_GE
: {
857 codecomp(fs
, cast(OpCode
, op
- OPR_NE
+ OP_EQ
), 0, e1
, e2
);
860 default: lua_assert(0);
865 void luaK_fixline (FuncState
*fs
, int line
) {
866 fs
->f
->lineinfo
[fs
->pc
- 1] = line
;
870 void luaK_setlist (FuncState
*fs
, int base
, int nelems
, int tostore
) {
871 int c
= (nelems
- 1)/LFIELDS_PER_FLUSH
+ 1;
872 int b
= (tostore
== LUA_MULTRET
) ? 0 : tostore
;
873 lua_assert(tostore
!= 0);
875 luaK_codeABC(fs
, OP_SETLIST
, base
, b
, c
);
876 else if (c
<= MAXARG_Ax
) {
877 luaK_codeABC(fs
, OP_SETLIST
, base
, b
, 0);
881 luaX_syntaxerror(fs
->ls
, "constructor too long");
882 fs
->freereg
= base
+ 1; /* free registers with list values */