2000-02-22 16:31:19 +03:00
|
|
|
/*
|
2003-05-14 16:09:12 +04:00
|
|
|
** $Id: lcode.c,v 1.117 2003/04/03 13:35:34 roberto Exp roberto $
|
2000-02-22 16:31:19 +03:00
|
|
|
** Code generator for Lua
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2001-02-23 23:31:37 +03:00
|
|
|
#include <stdlib.h>
|
2000-04-05 00:48:44 +04:00
|
|
|
|
2002-12-04 20:38:31 +03:00
|
|
|
#define lcode_c
|
|
|
|
|
2000-06-12 17:52:05 +04:00
|
|
|
#include "lua.h"
|
|
|
|
|
2000-02-22 16:31:19 +03:00
|
|
|
#include "lcode.h"
|
2001-06-05 22:17:01 +04:00
|
|
|
#include "ldebug.h"
|
2000-03-03 15:33:59 +03:00
|
|
|
#include "ldo.h"
|
2000-02-22 16:31:19 +03:00
|
|
|
#include "llex.h"
|
|
|
|
#include "lmem.h"
|
|
|
|
#include "lobject.h"
|
|
|
|
#include "lopcodes.h"
|
|
|
|
#include "lparser.h"
|
2001-08-27 19:16:28 +04:00
|
|
|
#include "ltable.h"
|
2000-03-03 15:33:59 +03:00
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
#define hasjumps(e) ((e)->t != (e)->f)
|
|
|
|
|
|
|
|
|
|
|
|
void luaK_nil (FuncState *fs, int from, int n) {
|
2002-01-18 20:39:40 +03:00
|
|
|
Instruction *previous;
|
|
|
|
if (fs->pc > fs->lasttarget && /* no jumps to current position? */
|
|
|
|
GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {
|
|
|
|
int pfrom = GETARG_A(*previous);
|
|
|
|
int pto = GETARG_B(*previous);
|
2001-06-05 22:17:01 +04:00
|
|
|
if (pfrom <= from && from <= pto+1) { /* can connect both? */
|
|
|
|
if (from+n-1 > pto)
|
2002-01-18 20:39:40 +03:00
|
|
|
SETARG_B(*previous, from+n-1);
|
2001-06-05 22:17:01 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */
|
2000-04-05 21:51:58 +04:00
|
|
|
}
|
|
|
|
|
2000-02-22 16:31:19 +03:00
|
|
|
|
2000-04-05 21:51:58 +04:00
|
|
|
int luaK_jump (FuncState *fs) {
|
2002-05-10 23:22:11 +04:00
|
|
|
int jpc = fs->jpc; /* save list of jumps to here */
|
|
|
|
int j;
|
|
|
|
fs->jpc = NO_JUMP;
|
|
|
|
j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
|
|
|
|
luaK_concat(fs, &j, jpc); /* keep them on hold */
|
2000-04-06 21:36:52 +04:00
|
|
|
return j;
|
2000-04-05 21:51:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-11 18:56:42 +04:00
|
|
|
static int luaK_condjump (FuncState *fs, OpCode op, int A, int B, int C) {
|
|
|
|
luaK_codeABC(fs, op, A, B, C);
|
2002-05-10 23:22:11 +04:00
|
|
|
return luaK_jump(fs);
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-05 21:51:58 +04:00
|
|
|
static void luaK_fixjump (FuncState *fs, int pc, int dest) {
|
2000-02-22 16:31:19 +03:00
|
|
|
Instruction *jmp = &fs->f->code[pc];
|
2002-05-10 23:22:11 +04:00
|
|
|
int offset = dest-(pc+1);
|
|
|
|
lua_assert(dest != NO_JUMP);
|
|
|
|
if (abs(offset) > MAXARG_sBx)
|
|
|
|
luaX_syntaxerror(fs->ls, "control structure too long");
|
|
|
|
SETARG_sBx(*jmp, offset);
|
2000-03-13 23:37:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-04 23:18:15 +03:00
|
|
|
/*
|
|
|
|
** returns current `pc' and marks it as a jump target (to avoid wrong
|
|
|
|
** optimizations with consecutive instructions not in the same basic block).
|
|
|
|
*/
|
2000-03-13 23:37:16 +03:00
|
|
|
int luaK_getlabel (FuncState *fs) {
|
2002-05-10 23:22:11 +04:00
|
|
|
fs->lasttarget = fs->pc;
|
2000-03-04 23:18:15 +03:00
|
|
|
return fs->pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
static int luaK_getjump (FuncState *fs, int pc) {
|
2002-04-25 00:07:46 +04:00
|
|
|
int offset = GETARG_sBx(fs->f->code[pc]);
|
2001-06-05 22:17:01 +04:00
|
|
|
if (offset == NO_JUMP) /* point to itself represents end of list */
|
|
|
|
return NO_JUMP; /* end of list */
|
|
|
|
else
|
|
|
|
return (pc+1)+offset; /* turn offset into absolute position */
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
static Instruction *getjumpcontrol (FuncState *fs, int pc) {
|
|
|
|
Instruction *pi = &fs->f->code[pc];
|
2003-05-14 16:09:12 +04:00
|
|
|
if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))
|
2001-06-05 22:17:01 +04:00
|
|
|
return pi-1;
|
2002-01-17 01:03:57 +03:00
|
|
|
else
|
2001-06-05 22:17:01 +04:00
|
|
|
return pi;
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-06 19:51:41 +04:00
|
|
|
/*
|
|
|
|
** check whether list has any jump that do not produce a value
|
|
|
|
** (or produce an inverted value)
|
|
|
|
*/
|
|
|
|
static int need_value (FuncState *fs, int list, int cond) {
|
|
|
|
for (; list != NO_JUMP; list = luaK_getjump(fs, list)) {
|
|
|
|
Instruction i = *getjumpcontrol(fs, list);
|
2002-08-21 00:03:05 +04:00
|
|
|
if (GET_OPCODE(i) != OP_TEST || GETARG_C(i) != cond) return 1;
|
2002-05-06 19:51:41 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
return 0; /* not found */
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-08 16:29:27 +04:00
|
|
|
static void patchtestreg (Instruction *i, int reg) {
|
2002-08-21 00:03:05 +04:00
|
|
|
if (reg == NO_REG) reg = GETARG_B(*i);
|
2001-06-08 16:29:27 +04:00
|
|
|
SETARG_A(*i, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
static void luaK_patchlistaux (FuncState *fs, int list,
|
|
|
|
int ttarget, int treg, int ftarget, int freg, int dtarget) {
|
|
|
|
while (list != NO_JUMP) {
|
|
|
|
int next = luaK_getjump(fs, list);
|
|
|
|
Instruction *i = getjumpcontrol(fs, list);
|
2002-05-06 19:51:41 +04:00
|
|
|
if (GET_OPCODE(*i) != OP_TEST) {
|
|
|
|
lua_assert(dtarget != NO_JUMP);
|
|
|
|
luaK_fixjump(fs, list, dtarget); /* jump to default target */
|
|
|
|
}
|
|
|
|
else {
|
2002-08-21 00:03:05 +04:00
|
|
|
if (GETARG_C(*i)) {
|
2002-05-06 19:51:41 +04:00
|
|
|
lua_assert(ttarget != NO_JUMP);
|
2001-06-08 16:29:27 +04:00
|
|
|
patchtestreg(i, treg);
|
2001-06-05 22:17:01 +04:00
|
|
|
luaK_fixjump(fs, list, ttarget);
|
|
|
|
}
|
2002-05-06 19:51:41 +04:00
|
|
|
else {
|
|
|
|
lua_assert(ftarget != NO_JUMP);
|
2001-06-08 16:29:27 +04:00
|
|
|
patchtestreg(i, freg);
|
2001-06-05 22:17:01 +04:00
|
|
|
luaK_fixjump(fs, list, ftarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list = next;
|
|
|
|
}
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-13 17:39:55 +04:00
|
|
|
static void luaK_dischargejpc (FuncState *fs) {
|
2002-05-13 17:07:48 +04:00
|
|
|
luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc);
|
|
|
|
fs->jpc = NO_JUMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
void luaK_patchlist (FuncState *fs, int list, int target) {
|
2002-05-13 17:07:48 +04:00
|
|
|
if (target == fs->pc)
|
|
|
|
luaK_patchtohere(fs, list);
|
|
|
|
else {
|
|
|
|
lua_assert(target < fs->pc);
|
|
|
|
luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target);
|
|
|
|
}
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-08 22:10:32 +03:00
|
|
|
void luaK_patchtohere (FuncState *fs, int list) {
|
2002-05-10 23:22:11 +04:00
|
|
|
luaK_getlabel(fs);
|
|
|
|
luaK_concat(fs, &fs->jpc, list);
|
2002-03-08 22:10:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
void luaK_concat (FuncState *fs, int *l1, int l2) {
|
2002-05-10 23:22:11 +04:00
|
|
|
if (l2 == NO_JUMP) return;
|
|
|
|
else if (*l1 == NO_JUMP)
|
2001-06-05 22:17:01 +04:00
|
|
|
*l1 = l2;
|
|
|
|
else {
|
|
|
|
int list = *l1;
|
|
|
|
int next;
|
|
|
|
while ((next = luaK_getjump(fs, list)) != NO_JUMP) /* find last element */
|
|
|
|
list = next;
|
|
|
|
luaK_fixjump(fs, list, l2);
|
|
|
|
}
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-11 15:34:22 +03:00
|
|
|
void luaK_checkstack (FuncState *fs, int n) {
|
2002-03-08 22:10:32 +03:00
|
|
|
int newstack = fs->freereg + n;
|
|
|
|
if (newstack > fs->f->maxstacksize) {
|
|
|
|
if (newstack >= MAXSTACK)
|
2002-05-07 21:36:56 +04:00
|
|
|
luaX_syntaxerror(fs->ls, "function or expression too complex");
|
2002-03-08 22:10:32 +03:00
|
|
|
fs->f->maxstacksize = cast(lu_byte, newstack);
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-08 22:10:32 +03:00
|
|
|
void luaK_reserveregs (FuncState *fs, int n) {
|
|
|
|
luaK_checkstack(fs, n);
|
|
|
|
fs->freereg += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
static void freereg (FuncState *fs, int reg) {
|
2002-05-14 21:52:22 +04:00
|
|
|
if (reg >= fs->nactvar && reg < MAXSTACK) {
|
2001-06-05 22:17:01 +04:00
|
|
|
fs->freereg--;
|
|
|
|
lua_assert(reg == fs->freereg);
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
2000-03-04 23:18:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
static void freeexp (FuncState *fs, expdesc *e) {
|
|
|
|
if (e->k == VNONRELOC)
|
2002-01-26 00:50:39 +03:00
|
|
|
freereg(fs, e->info);
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
2000-04-07 23:35:20 +04:00
|
|
|
|
2000-03-03 15:33:59 +03:00
|
|
|
|
2001-12-12 01:48:44 +03:00
|
|
|
static int addk (FuncState *fs, TObject *k, TObject *v) {
|
2003-02-27 15:33:07 +03:00
|
|
|
const TObject *idx = luaH_get(fs->h, k);
|
|
|
|
if (ttisnumber(idx)) {
|
|
|
|
lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(idx))], v));
|
|
|
|
return cast(int, nvalue(idx));
|
2001-08-27 19:16:28 +04:00
|
|
|
}
|
|
|
|
else { /* constant not found; create a new entry */
|
|
|
|
Proto *f = fs->f;
|
|
|
|
luaM_growvector(fs->L, f->k, fs->nk, f->sizek, TObject,
|
2002-04-25 00:07:46 +04:00
|
|
|
MAXARG_Bx, "constant table overflow");
|
2002-11-14 19:15:53 +03:00
|
|
|
setobj2n(&f->k[fs->nk], v);
|
2003-04-03 17:35:34 +04:00
|
|
|
setnvalue(luaH_set(fs->L, fs->h, k), cast(lua_Number, fs->nk));
|
2001-08-27 19:16:28 +04:00
|
|
|
return fs->nk++;
|
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-26 00:50:39 +03:00
|
|
|
int luaK_stringK (FuncState *fs, TString *s) {
|
2001-08-27 19:16:28 +04:00
|
|
|
TObject o;
|
|
|
|
setsvalue(&o, s);
|
2001-12-12 01:48:44 +03:00
|
|
|
return addk(fs, &o, &o);
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-26 00:50:39 +03:00
|
|
|
int luaK_numberK (FuncState *fs, lua_Number r) {
|
2001-06-05 22:17:01 +04:00
|
|
|
TObject o;
|
|
|
|
setnvalue(&o, r);
|
2001-12-12 01:48:44 +03:00
|
|
|
return addk(fs, &o, &o);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int nil_constant (FuncState *fs) {
|
|
|
|
TObject k, v;
|
|
|
|
setnilvalue(&v);
|
|
|
|
sethvalue(&k, fs->h); /* cannot use nil as key; instead use table itself */
|
|
|
|
return addk(fs, &k, &v);
|
2000-03-09 16:57:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
void luaK_setcallreturns (FuncState *fs, expdesc *e, int nresults) {
|
|
|
|
if (e->k == VCALL) { /* expression is an open function call? */
|
2002-01-10 01:02:47 +03:00
|
|
|
SETARG_C(getcode(fs, e), nresults+1);
|
2001-06-05 22:17:01 +04:00
|
|
|
if (nresults == 1) { /* `regular' expression? */
|
|
|
|
e->k = VNONRELOC;
|
2002-01-26 00:50:39 +03:00
|
|
|
e->info = GETARG_A(getcode(fs, e));
|
2000-03-09 16:57:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-12 18:36:48 +04:00
|
|
|
void luaK_dischargevars (FuncState *fs, expdesc *e) {
|
2001-06-05 22:17:01 +04:00
|
|
|
switch (e->k) {
|
|
|
|
case VLOCAL: {
|
|
|
|
e->k = VNONRELOC;
|
|
|
|
break;
|
|
|
|
}
|
2001-09-07 21:39:10 +04:00
|
|
|
case VUPVAL: {
|
2002-01-26 00:50:39 +03:00
|
|
|
e->info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->info, 0);
|
2001-09-07 21:39:10 +04:00
|
|
|
e->k = VRELOCABLE;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
case VGLOBAL: {
|
2002-04-25 00:07:46 +04:00
|
|
|
e->info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->info);
|
2001-06-05 22:17:01 +04:00
|
|
|
e->k = VRELOCABLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VINDEXED: {
|
2002-01-26 00:50:39 +03:00
|
|
|
freereg(fs, e->aux);
|
|
|
|
freereg(fs, e->info);
|
|
|
|
e->info = luaK_codeABC(fs, OP_GETTABLE, 0, e->info, e->aux);
|
2001-06-05 22:17:01 +04:00
|
|
|
e->k = VRELOCABLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VCALL: {
|
|
|
|
luaK_setcallreturns(fs, e, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break; /* there is one value available (somewhere) */
|
|
|
|
}
|
2000-03-09 16:57:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-12 01:48:44 +03:00
|
|
|
static int code_label (FuncState *fs, int A, int b, int jump) {
|
2001-06-05 22:17:01 +04:00
|
|
|
luaK_getlabel(fs); /* those instructions may be jump targets */
|
2001-12-12 01:48:44 +03:00
|
|
|
return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
|
2000-03-09 16:57:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
|
2001-06-12 18:36:48 +04:00
|
|
|
luaK_dischargevars(fs, e);
|
2001-06-05 22:17:01 +04:00
|
|
|
switch (e->k) {
|
|
|
|
case VNIL: {
|
|
|
|
luaK_nil(fs, reg, 1);
|
|
|
|
break;
|
|
|
|
}
|
2001-12-12 01:48:44 +03:00
|
|
|
case VFALSE: case VTRUE: {
|
|
|
|
luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
|
|
|
|
break;
|
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
case VK: {
|
2002-04-25 00:07:46 +04:00
|
|
|
luaK_codeABx(fs, OP_LOADK, reg, e->info);
|
2001-06-05 22:17:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VRELOCABLE: {
|
|
|
|
Instruction *pc = &getcode(fs, e);
|
|
|
|
SETARG_A(*pc, reg);
|
|
|
|
break;
|
|
|
|
}
|
2002-04-22 18:37:09 +04:00
|
|
|
case VNONRELOC: {
|
|
|
|
if (reg != e->info)
|
|
|
|
luaK_codeABC(fs, OP_MOVE, reg, e->info, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
lua_assert(e->k == VVOID || e->k == VJMP);
|
|
|
|
return; /* nothing to do... */
|
|
|
|
}
|
2000-03-24 15:18:30 +03:00
|
|
|
}
|
2002-01-26 00:50:39 +03:00
|
|
|
e->info = reg;
|
2001-06-05 22:17:01 +04:00
|
|
|
e->k = VNONRELOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void discharge2anyreg (FuncState *fs, expdesc *e) {
|
|
|
|
if (e->k != VNONRELOC) {
|
|
|
|
luaK_reserveregs(fs, 1);
|
|
|
|
discharge2reg(fs, e, fs->freereg-1);
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2000-03-24 15:18:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) {
|
|
|
|
discharge2reg(fs, e, reg);
|
2002-05-09 18:14:34 +04:00
|
|
|
if (e->k == VJMP)
|
|
|
|
luaK_concat(fs, &e->t, e->info); /* put this jump in `t' list */
|
|
|
|
if (hasjumps(e)) {
|
2002-04-22 18:37:09 +04:00
|
|
|
int final; /* position after whole expression */
|
2002-05-09 18:14:34 +04:00
|
|
|
int p_f = NO_JUMP; /* position of an eventual LOAD false */
|
|
|
|
int p_t = NO_JUMP; /* position of an eventual LOAD true */
|
|
|
|
if (need_value(fs, e->t, 1) || need_value(fs, e->f, 0)) {
|
2002-05-13 17:07:48 +04:00
|
|
|
int fj = NO_JUMP; /* first jump (over LOAD ops.) */
|
|
|
|
if (e->k != VJMP)
|
|
|
|
fj = luaK_jump(fs);
|
2002-05-09 18:14:34 +04:00
|
|
|
p_f = code_label(fs, reg, 0, 1);
|
|
|
|
p_t = code_label(fs, reg, 1, 0);
|
2002-05-13 17:07:48 +04:00
|
|
|
luaK_patchtohere(fs, fj);
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
2002-04-22 18:37:09 +04:00
|
|
|
final = luaK_getlabel(fs);
|
|
|
|
luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f);
|
|
|
|
luaK_patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t);
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
2002-04-22 18:37:09 +04:00
|
|
|
e->f = e->t = NO_JUMP;
|
2002-01-26 00:50:39 +03:00
|
|
|
e->info = reg;
|
2001-06-05 22:17:01 +04:00
|
|
|
e->k = VNONRELOC;
|
2000-03-09 16:57:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
|
2001-06-12 18:36:48 +04:00
|
|
|
luaK_dischargevars(fs, e);
|
2001-06-05 22:17:01 +04:00
|
|
|
freeexp(fs, e);
|
|
|
|
luaK_reserveregs(fs, 1);
|
2002-04-22 18:37:09 +04:00
|
|
|
luaK_exp2reg(fs, e, fs->freereg - 1);
|
2000-03-09 16:57:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
|
2001-06-12 18:36:48 +04:00
|
|
|
luaK_dischargevars(fs, e);
|
2001-06-05 22:17:01 +04:00
|
|
|
if (e->k == VNONRELOC) {
|
2002-01-26 00:50:39 +03:00
|
|
|
if (!hasjumps(e)) return e->info; /* exp is already in a register */
|
2002-05-14 21:52:22 +04:00
|
|
|
if (e->info >= fs->nactvar) { /* reg. is not a local? */
|
2002-04-22 18:37:09 +04:00
|
|
|
luaK_exp2reg(fs, e, e->info); /* put value on it */
|
2002-01-26 00:50:39 +03:00
|
|
|
return e->info;
|
2000-04-17 18:05:34 +04:00
|
|
|
}
|
2000-03-09 16:57:37 +03:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
luaK_exp2nextreg(fs, e); /* default */
|
2002-01-26 00:50:39 +03:00
|
|
|
return e->info;
|
2000-03-09 16:57:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
void luaK_exp2val (FuncState *fs, expdesc *e) {
|
|
|
|
if (hasjumps(e))
|
|
|
|
luaK_exp2anyreg(fs, e);
|
|
|
|
else
|
2001-06-12 18:36:48 +04:00
|
|
|
luaK_dischargevars(fs, e);
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
int luaK_exp2RK (FuncState *fs, expdesc *e) {
|
|
|
|
luaK_exp2val(fs, e);
|
2001-12-12 01:48:44 +03:00
|
|
|
switch (e->k) {
|
2002-01-26 00:50:39 +03:00
|
|
|
case VNIL: {
|
2001-12-12 01:48:44 +03:00
|
|
|
if (fs->nk + MAXSTACK <= MAXARG_C) { /* constant fit in argC? */
|
2002-01-26 00:50:39 +03:00
|
|
|
e->info = nil_constant(fs);
|
2001-12-12 01:48:44 +03:00
|
|
|
e->k = VK;
|
2002-01-26 00:50:39 +03:00
|
|
|
return e->info + MAXSTACK;
|
2001-12-12 01:48:44 +03:00
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
case VK: {
|
2002-01-26 00:50:39 +03:00
|
|
|
if (e->info + MAXSTACK <= MAXARG_C) /* constant fit in argC? */
|
|
|
|
return e->info + MAXSTACK;
|
2001-12-12 01:48:44 +03:00
|
|
|
else break;
|
|
|
|
}
|
|
|
|
default: break;
|
2000-08-09 18:49:13 +04:00
|
|
|
}
|
2002-08-21 00:03:05 +04:00
|
|
|
/* not a constant in the right range: put it in a register */
|
2001-12-12 01:48:44 +03:00
|
|
|
return luaK_exp2anyreg(fs, e);
|
2000-04-07 23:35:20 +04:00
|
|
|
}
|
2000-03-03 15:33:59 +03:00
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
void luaK_storevar (FuncState *fs, expdesc *var, expdesc *exp) {
|
|
|
|
switch (var->k) {
|
|
|
|
case VLOCAL: {
|
|
|
|
freeexp(fs, exp);
|
2002-01-26 00:50:39 +03:00
|
|
|
luaK_exp2reg(fs, exp, var->info);
|
2002-04-22 18:37:09 +04:00
|
|
|
return;
|
2000-08-09 18:49:13 +04:00
|
|
|
}
|
2001-09-07 21:39:10 +04:00
|
|
|
case VUPVAL: {
|
|
|
|
int e = luaK_exp2anyreg(fs, exp);
|
2002-01-26 00:50:39 +03:00
|
|
|
luaK_codeABC(fs, OP_SETUPVAL, e, var->info, 0);
|
2001-09-07 21:39:10 +04:00
|
|
|
break;
|
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
case VGLOBAL: {
|
|
|
|
int e = luaK_exp2anyreg(fs, exp);
|
2002-04-25 00:07:46 +04:00
|
|
|
luaK_codeABx(fs, OP_SETGLOBAL, e, var->info);
|
2001-06-05 22:17:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VINDEXED: {
|
2002-08-21 00:03:05 +04:00
|
|
|
int e = luaK_exp2RK(fs, exp);
|
|
|
|
luaK_codeABC(fs, OP_SETTABLE, var->info, var->aux, e);
|
2000-08-09 18:49:13 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2001-06-05 22:17:01 +04:00
|
|
|
lua_assert(0); /* invalid var kind to store */
|
|
|
|
break;
|
2000-03-09 16:57:37 +03:00
|
|
|
}
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
2002-04-22 18:37:09 +04:00
|
|
|
freeexp(fs, exp);
|
2000-03-03 15:33:59 +03:00
|
|
|
}
|
|
|
|
|
2000-04-07 23:35:20 +04:00
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
|
2001-07-17 18:30:44 +04:00
|
|
|
int func;
|
2001-06-05 22:17:01 +04:00
|
|
|
luaK_exp2anyreg(fs, e);
|
|
|
|
freeexp(fs, e);
|
2001-07-17 18:30:44 +04:00
|
|
|
func = fs->freereg;
|
2001-06-05 22:17:01 +04:00
|
|
|
luaK_reserveregs(fs, 2);
|
2002-01-26 00:50:39 +03:00
|
|
|
luaK_codeABC(fs, OP_SELF, func, e->info, luaK_exp2RK(fs, key));
|
2001-07-17 18:30:44 +04:00
|
|
|
freeexp(fs, key);
|
2002-01-26 00:50:39 +03:00
|
|
|
e->info = func;
|
2001-06-05 22:17:01 +04:00
|
|
|
e->k = VNONRELOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void invertjump (FuncState *fs, expdesc *e) {
|
2002-01-26 00:50:39 +03:00
|
|
|
Instruction *pc = getjumpcontrol(fs, e->info);
|
2003-05-14 16:09:12 +04:00
|
|
|
lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TEST);
|
2002-08-21 00:03:05 +04:00
|
|
|
SETARG_A(*pc, !(GETARG_A(*pc)));
|
2000-04-07 23:35:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-06 19:51:41 +04:00
|
|
|
static int jumponcond (FuncState *fs, expdesc *e, int cond) {
|
2001-06-05 22:17:01 +04:00
|
|
|
if (e->k == VRELOCABLE) {
|
|
|
|
Instruction ie = getcode(fs, e);
|
|
|
|
if (GET_OPCODE(ie) == OP_NOT) {
|
|
|
|
fs->pc--; /* remove previous OP_NOT */
|
2002-08-21 00:03:05 +04:00
|
|
|
return luaK_condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond);
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
/* else go through */
|
|
|
|
}
|
|
|
|
discharge2anyreg(fs, e);
|
|
|
|
freeexp(fs, e);
|
2002-08-21 00:03:05 +04:00
|
|
|
return luaK_condjump(fs, OP_TEST, NO_REG, e->info, cond);
|
2000-04-07 23:35:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
void luaK_goiftrue (FuncState *fs, expdesc *e) {
|
|
|
|
int pc; /* pc of last jump */
|
2001-06-12 18:36:48 +04:00
|
|
|
luaK_dischargevars(fs, e);
|
2001-06-05 22:17:01 +04:00
|
|
|
switch (e->k) {
|
2002-01-26 00:50:39 +03:00
|
|
|
case VK: case VTRUE: {
|
2001-06-05 22:17:01 +04:00
|
|
|
pc = NO_JUMP; /* always true; do nothing */
|
2000-04-14 21:47:24 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-12-12 01:48:44 +03:00
|
|
|
case VFALSE: {
|
2002-05-10 23:22:11 +04:00
|
|
|
pc = luaK_jump(fs); /* always jump */
|
2000-06-05 18:56:18 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
case VJMP: {
|
|
|
|
invertjump(fs, e);
|
2002-01-26 00:50:39 +03:00
|
|
|
pc = e->info;
|
2000-04-14 21:47:24 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
default: {
|
2002-05-06 19:51:41 +04:00
|
|
|
pc = jumponcond(fs, e, 0);
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-10 21:02:32 +04:00
|
|
|
void luaK_goiffalse (FuncState *fs, expdesc *e) {
|
2001-06-05 22:17:01 +04:00
|
|
|
int pc; /* pc of last jump */
|
2001-06-12 18:36:48 +04:00
|
|
|
luaK_dischargevars(fs, e);
|
2001-06-05 22:17:01 +04:00
|
|
|
switch (e->k) {
|
2001-12-12 01:48:44 +03:00
|
|
|
case VNIL: case VFALSE: {
|
2001-06-05 22:17:01 +04:00
|
|
|
pc = NO_JUMP; /* always false; do nothing */
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-12-12 01:48:44 +03:00
|
|
|
case VTRUE: {
|
2002-05-10 23:22:11 +04:00
|
|
|
pc = luaK_jump(fs); /* always jump */
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-12-12 01:48:44 +03:00
|
|
|
case VJMP: {
|
2002-01-26 00:50:39 +03:00
|
|
|
pc = e->info;
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
default: {
|
2002-05-06 19:51:41 +04:00
|
|
|
pc = jumponcond(fs, e, 1);
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void codenot (FuncState *fs, expdesc *e) {
|
2001-06-12 18:36:48 +04:00
|
|
|
luaK_dischargevars(fs, e);
|
2001-06-05 22:17:01 +04:00
|
|
|
switch (e->k) {
|
2001-12-12 01:48:44 +03:00
|
|
|
case VNIL: case VFALSE: {
|
|
|
|
e->k = VTRUE;
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2002-01-26 00:50:39 +03:00
|
|
|
case VK: case VTRUE: {
|
2001-12-12 01:48:44 +03:00
|
|
|
e->k = VFALSE;
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
case VJMP: {
|
|
|
|
invertjump(fs, e);
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
case VRELOCABLE:
|
|
|
|
case VNONRELOC: {
|
|
|
|
discharge2anyreg(fs, e);
|
|
|
|
freeexp(fs, e);
|
2002-01-26 00:50:39 +03:00
|
|
|
e->info = luaK_codeABC(fs, OP_NOT, 0, e->info, 0);
|
2001-06-05 22:17:01 +04:00
|
|
|
e->k = VRELOCABLE;
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
default: {
|
|
|
|
lua_assert(0); /* cannot happen */
|
2000-06-16 21:51:40 +04:00
|
|
|
break;
|
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
/* interchange true and false lists */
|
|
|
|
{ int temp = e->f; e->f = e->t; e->t = temp; }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
|
2002-01-26 00:50:39 +03:00
|
|
|
t->aux = luaK_exp2RK(fs, k);
|
2001-06-05 22:17:01 +04:00
|
|
|
t->k = VINDEXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
|
|
|
|
if (op == OPR_MINUS) {
|
|
|
|
luaK_exp2val(fs, e);
|
2002-08-05 18:50:39 +04:00
|
|
|
if (e->k == VK && ttisnumber(&fs->f->k[e->info]))
|
2002-01-26 00:50:39 +03:00
|
|
|
e->info = luaK_numberK(fs, -nvalue(&fs->f->k[e->info]));
|
2001-06-05 22:17:01 +04:00
|
|
|
else {
|
|
|
|
luaK_exp2anyreg(fs, e);
|
|
|
|
freeexp(fs, e);
|
2002-01-26 00:50:39 +03:00
|
|
|
e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0);
|
2001-06-05 22:17:01 +04:00
|
|
|
e->k = VRELOCABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* op == NOT */
|
|
|
|
codenot(fs, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
|
|
|
|
switch (op) {
|
|
|
|
case OPR_AND: {
|
|
|
|
luaK_goiftrue(fs, v);
|
2002-05-10 21:02:32 +04:00
|
|
|
luaK_patchtohere(fs, v->t);
|
|
|
|
v->t = NO_JUMP;
|
2001-06-05 22:17:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPR_OR: {
|
|
|
|
luaK_goiffalse(fs, v);
|
2002-05-10 21:02:32 +04:00
|
|
|
luaK_patchtohere(fs, v->f);
|
|
|
|
v->f = NO_JUMP;
|
2001-06-05 22:17:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPR_CONCAT: {
|
|
|
|
luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
|
2000-04-07 23:35:20 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
|
|
|
default: {
|
2001-06-05 22:17:01 +04:00
|
|
|
luaK_exp2RK(fs, v);
|
2000-05-22 22:44:46 +04:00
|
|
|
break;
|
2000-06-16 21:51:40 +04:00
|
|
|
}
|
2000-04-07 23:35:20 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-06 19:51:41 +04:00
|
|
|
static void codebinop (FuncState *fs, expdesc *res, BinOpr op,
|
2002-08-21 00:03:05 +04:00
|
|
|
int o1, int o2) {
|
2002-08-21 22:56:33 +04:00
|
|
|
if (op <= OPR_POW) { /* arithmetic operator? */
|
|
|
|
OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD); /* ORDER OP */
|
|
|
|
res->info = luaK_codeABC(fs, opc, 0, o1, o2);
|
|
|
|
res->k = VRELOCABLE;
|
|
|
|
}
|
|
|
|
else { /* test operator */
|
|
|
|
static const OpCode ops[] = {OP_EQ, OP_EQ, OP_LT, OP_LE, OP_LT, OP_LE};
|
|
|
|
int cond = 1;
|
|
|
|
if (op >= OPR_GT) { /* `>' or `>='? */
|
|
|
|
int temp; /* exchange args and replace by `<' or `<=' */
|
2002-08-21 00:03:05 +04:00
|
|
|
temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */
|
2002-05-06 19:51:41 +04:00
|
|
|
}
|
2002-08-21 22:56:33 +04:00
|
|
|
else if (op == OPR_NE) cond = 0;
|
|
|
|
res->info = luaK_condjump(fs, ops[op - OPR_NE], cond, o1, o2);
|
|
|
|
res->k = VJMP;
|
2002-05-06 19:51:41 +04:00
|
|
|
}
|
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
|
|
|
|
switch (op) {
|
|
|
|
case OPR_AND: {
|
|
|
|
lua_assert(e1->t == NO_JUMP); /* list must be closed */
|
2001-06-12 18:36:48 +04:00
|
|
|
luaK_dischargevars(fs, e2);
|
2001-06-05 22:17:01 +04:00
|
|
|
luaK_concat(fs, &e1->f, e2->f);
|
2002-01-26 00:50:39 +03:00
|
|
|
e1->k = e2->k; e1->info = e2->info; e1->aux = e2->aux; e1->t = e2->t;
|
2001-06-05 22:17:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPR_OR: {
|
|
|
|
lua_assert(e1->f == NO_JUMP); /* list must be closed */
|
2001-06-12 18:36:48 +04:00
|
|
|
luaK_dischargevars(fs, e2);
|
2001-06-05 22:17:01 +04:00
|
|
|
luaK_concat(fs, &e1->t, e2->t);
|
2002-01-26 00:50:39 +03:00
|
|
|
e1->k = e2->k; e1->info = e2->info; e1->aux = e2->aux; e1->f = e2->f;
|
2001-06-05 22:17:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPR_CONCAT: {
|
|
|
|
luaK_exp2val(fs, e2);
|
|
|
|
if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
|
2002-01-26 00:50:39 +03:00
|
|
|
lua_assert(e1->info == GETARG_B(getcode(fs, e2))-1);
|
2001-06-05 22:17:01 +04:00
|
|
|
freeexp(fs, e1);
|
2002-01-26 00:50:39 +03:00
|
|
|
SETARG_B(getcode(fs, e2), e1->info);
|
|
|
|
e1->k = e2->k; e1->info = e2->info;
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
luaK_exp2nextreg(fs, e2);
|
|
|
|
freeexp(fs, e2);
|
|
|
|
freeexp(fs, e1);
|
2002-04-03 00:43:08 +04:00
|
|
|
e1->info = luaK_codeABC(fs, OP_CONCAT, 0, e1->info, e2->info);
|
2001-06-05 22:17:01 +04:00
|
|
|
e1->k = VRELOCABLE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2002-08-21 00:03:05 +04:00
|
|
|
int o1 = luaK_exp2RK(fs, e1);
|
|
|
|
int o2 = luaK_exp2RK(fs, e2);
|
2001-06-05 22:17:01 +04:00
|
|
|
freeexp(fs, e2);
|
|
|
|
freeexp(fs, e1);
|
2002-08-21 00:03:05 +04:00
|
|
|
codebinop(fs, e1, op, o1, o2);
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
2000-05-22 22:44:46 +04:00
|
|
|
}
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-13 17:07:48 +04:00
|
|
|
void luaK_fixline (FuncState *fs, int line) {
|
|
|
|
fs->f->lineinfo[fs->pc - 1] = line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-10 21:02:32 +04:00
|
|
|
int luaK_code (FuncState *fs, Instruction i, int line) {
|
2002-03-25 20:47:14 +03:00
|
|
|
Proto *f = fs->f;
|
2002-05-10 23:22:11 +04:00
|
|
|
luaK_dischargejpc(fs); /* `pc' will change */
|
2000-06-21 22:13:56 +04:00
|
|
|
/* put new instruction in code array */
|
2000-12-28 15:55:41 +03:00
|
|
|
luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
|
2001-11-28 23:13:13 +03:00
|
|
|
MAX_INT, "code size overflow");
|
2000-12-28 15:55:41 +03:00
|
|
|
f->code[fs->pc] = i;
|
2002-10-17 00:40:58 +04:00
|
|
|
/* save corresponding line information */
|
|
|
|
luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
|
|
|
|
MAX_INT, "code size overflow");
|
2002-05-10 21:02:32 +04:00
|
|
|
f->lineinfo[fs->pc] = line;
|
2000-04-07 23:35:20 +04:00
|
|
|
return fs->pc++;
|
|
|
|
}
|
|
|
|
|
2000-05-22 22:44:46 +04:00
|
|
|
|
2001-06-05 22:17:01 +04:00
|
|
|
int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {
|
|
|
|
lua_assert(getOpMode(o) == iABC);
|
2003-05-14 16:09:12 +04:00
|
|
|
lua_assert(getBMode(o) != OpArgN || b == 0);
|
|
|
|
lua_assert(getCMode(o) != OpArgN || c == 0);
|
2002-05-10 21:02:32 +04:00
|
|
|
return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline);
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-25 00:07:46 +04:00
|
|
|
int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {
|
|
|
|
lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
|
2003-05-14 16:09:12 +04:00
|
|
|
lua_assert(getCMode(o) == OpArgN);
|
2002-05-10 21:02:32 +04:00
|
|
|
return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline);
|
2001-06-05 22:17:01 +04:00
|
|
|
}
|
2000-06-29 00:21:06 +04:00
|
|
|
|