lua/lvm.c

608 lines
16 KiB
C
Raw Normal View History

1997-09-16 23:25:59 +04:00
/*
** $Id: lvm.c,v 1.73 1999/12/14 18:31:20 roberto Exp roberto $
1997-09-16 23:25:59 +04:00
** Lua virtual machine
** See Copyright Notice in lua.h
*/
#include <stdio.h>
#include <stdlib.h>
1997-09-16 23:25:59 +04:00
#include <string.h>
#define LUA_REENTRANT
1997-09-16 23:25:59 +04:00
#include "lauxlib.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lobject.h"
1997-09-16 23:25:59 +04:00
#include "lopcodes.h"
#include "lstate.h"
1997-09-16 23:25:59 +04:00
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lvm.h"
#ifdef OLD_ANSI
#define strcoll(a,b) strcmp(a,b)
#endif
#define highbyte(L, x) ((x)<<8)
1997-09-16 23:25:59 +04:00
/* Extra stack size to run a function: LUA_T_LINE(1), TM calls(2), ... */
#define EXTRA_STACK 5
1997-09-16 23:25:59 +04:00
1999-11-30 16:06:50 +03:00
static TaggedString *strconc (lua_State *L, const TaggedString *l,
const TaggedString *r) {
long nl = l->u.s.len;
long nr = r->u.s.len;
char *buffer = luaL_openspace(L, nl+nr);
1998-03-06 19:54:42 +03:00
memcpy(buffer, l->str, nl);
memcpy(buffer+nl, r->str, nr);
return luaS_newlstr(L, buffer, nl+nr);
1997-09-16 23:25:59 +04:00
}
int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
1997-09-16 23:25:59 +04:00
if (ttype(obj) != LUA_T_STRING)
return 1;
else {
if (!luaO_str2d(svalue(obj), &nvalue(obj)))
1999-04-13 23:28:49 +04:00
return 2;
1997-09-16 23:25:59 +04:00
ttype(obj) = LUA_T_NUMBER;
return 0;
}
}
int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */
1997-09-16 23:25:59 +04:00
if (ttype(obj) != LUA_T_NUMBER)
return 1;
else {
1999-12-14 21:33:29 +03:00
char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */
sprintf(s, "%.16g", (double)nvalue(obj));
tsvalue(obj) = luaS_new(L, s);
1997-09-16 23:25:59 +04:00
ttype(obj) = LUA_T_STRING;
return 0;
}
}
void luaV_setn (lua_State *L, Hash *t, int val) {
1998-12-30 16:16:50 +03:00
TObject index, value;
ttype(&index) = LUA_T_STRING; tsvalue(&index) = luaS_new(L, "n");
1998-12-30 20:26:49 +03:00
ttype(&value) = LUA_T_NUMBER; nvalue(&value) = val;
luaH_set(L, t, &index, &value);
1998-12-30 16:16:50 +03:00
}
void luaV_closure (lua_State *L, int nelems) {
if (nelems > 0) {
Closure *c = luaF_newclosure(L, nelems);
1999-12-01 22:50:08 +03:00
c->consts[0] = *(L->top-1);
L->top -= nelems;
memcpy(&c->consts[1], L->top-1, nelems*sizeof(TObject));
ttype(L->top-1) = LUA_T_CLOSURE;
(L->top-1)->value.cl = c;
}
1997-09-16 23:25:59 +04:00
}
/*
** Function to index a table.
** Receives the table at top-2 and the index at top-1.
*/
void luaV_gettable (lua_State *L) {
1999-12-01 22:50:08 +03:00
TObject *table = L->top-2;
1999-08-17 00:52:00 +04:00
const TObject *im;
1999-02-08 20:07:59 +03:00
if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */
im = luaT_getimbyObj(L, table, IM_GETTABLE);
1999-02-08 20:07:59 +03:00
if (ttype(im) == LUA_T_NIL)
lua_error(L, "indexed expression not a table");
1999-02-08 20:07:59 +03:00
}
1997-09-16 23:25:59 +04:00
else { /* object is a table... */
1999-02-08 20:07:59 +03:00
int tg = table->value.a->htag;
im = luaT_getim(L, tg, IM_GETTABLE);
1999-12-06 14:40:55 +03:00
if (ttype(im) == LUA_T_NIL) { /* and does not have a `gettable' method */
const TObject *h = luaH_get(L, avalue(table), table+1);
1999-02-08 20:07:59 +03:00
if (ttype(h) == LUA_T_NIL &&
(ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) {
1999-12-06 14:40:55 +03:00
/* result is nil and there is an `index' tag method */
luaD_callTM(L, im, 2, 1); /* calls it */
1997-09-16 23:25:59 +04:00
}
else {
1999-12-01 22:50:08 +03:00
L->top--;
1999-12-06 14:40:55 +03:00
*table = *h; /* `push' result into table position */
1997-09-16 23:25:59 +04:00
}
return;
}
1999-12-06 14:40:55 +03:00
/* else it has a `gettable' method, go through to next command */
1997-09-16 23:25:59 +04:00
}
1999-12-06 14:40:55 +03:00
/* object is not a table, or it has a `gettable' method */
luaD_callTM(L, im, 2, 1);
1997-09-16 23:25:59 +04:00
}
/*
1999-02-08 20:07:59 +03:00
** Receives table at *t, index at *(t+1) and value at top.
1997-09-16 23:25:59 +04:00
*/
1999-12-01 22:50:08 +03:00
void luaV_settable (lua_State *L, StkId t) {
1999-08-17 00:52:00 +04:00
const TObject *im;
1999-02-08 20:07:59 +03:00
if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */
im = luaT_getimbyObj(L, t, IM_SETTABLE);
1999-02-08 20:07:59 +03:00
if (ttype(im) == LUA_T_NIL)
lua_error(L, "indexed expression not a table");
1999-02-08 20:07:59 +03:00
}
1998-12-30 20:26:49 +03:00
else { /* object is a table... */
im = luaT_getim(L, avalue(t)->htag, IM_SETTABLE);
1998-12-30 20:26:49 +03:00
if (ttype(im) == LUA_T_NIL) { /* and does not have a "settable" method */
1999-12-01 22:50:08 +03:00
luaH_set(L, avalue(t), t+1, L->top-1);
L->top--; /* pop value */
1998-12-30 20:26:49 +03:00
return;
1997-09-16 23:25:59 +04:00
}
1998-12-30 20:26:49 +03:00
/* else it has a "settable" method, go through to next command */
}
/* object is not a table, or it has a "settable" method */
1999-02-08 20:07:59 +03:00
/* prepare arguments and call the tag method */
1999-12-01 22:50:08 +03:00
*(L->top+1) = *(L->top-1);
*(L->top) = *(t+1);
*(L->top-1) = *t;
L->top += 2; /* WARNING: caller must assure stack space */
luaD_callTM(L, im, 3, 0);
1998-12-30 20:26:49 +03:00
}
1999-12-01 22:50:08 +03:00
void luaV_rawsettable (lua_State *L, StkId t) {
1998-12-30 20:26:49 +03:00
if (ttype(t) != LUA_T_ARRAY)
lua_error(L, "indexed expression not a table");
1998-12-30 20:26:49 +03:00
else {
1999-12-01 22:50:08 +03:00
luaH_set(L, avalue(t), t+1, L->top-1);
L->top -= 3;
1997-09-16 23:25:59 +04:00
}
}
void luaV_getglobal (lua_State *L, GlobalVar *gv) {
1999-01-20 23:22:06 +03:00
/* WARNING: caller must assure stack space */
const TObject *value = &gv->value;
TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL);
if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */
ttype(L->top) = LUA_T_STRING;
tsvalue(L->top) = gv->name; /* global name */
L->top++;
*L->top++ = *value;
luaD_callTM(L, im, 2, 1);
} else { /* no tag method */
*L->top++ = *value; /* default behavior */
1997-09-16 23:25:59 +04:00
}
}
void luaV_setglobal (lua_State *L, GlobalVar *gv) {
const TObject *oldvalue = &gv->value;
const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL);
1999-01-15 16:14:24 +03:00
if (ttype(im) == LUA_T_NIL) /* is there a tag method? */
1999-12-01 22:50:08 +03:00
gv->value = *(--L->top);
1997-09-16 23:25:59 +04:00
else {
/* WARNING: caller must assure stack space */
TObject newvalue;
1999-12-01 22:50:08 +03:00
newvalue = *(L->top-1);
ttype(L->top-1) = LUA_T_STRING;
tsvalue(L->top-1) = gv->name;
*L->top++ = *oldvalue;
*L->top++ = newvalue;
luaD_callTM(L, im, 3, 0);
1997-09-16 23:25:59 +04:00
}
}
1999-12-01 22:50:08 +03:00
static void call_binTM (lua_State *L, StkId top, IMS event, const char *msg) {
1999-08-17 00:52:00 +04:00
/* try first operand */
1999-12-01 22:50:08 +03:00
const TObject *im = luaT_getimbyObj(L, top-2, event);
L->top = top;
1997-09-16 23:25:59 +04:00
if (ttype(im) == LUA_T_NIL) {
1999-12-01 22:50:08 +03:00
im = luaT_getimbyObj(L, top-1, event); /* try second operand */
1997-09-16 23:25:59 +04:00
if (ttype(im) == LUA_T_NIL) {
im = luaT_getim(L, 0, event); /* try a 'global' i.m. */
1997-09-16 23:25:59 +04:00
if (ttype(im) == LUA_T_NIL)
lua_error(L, msg);
1997-09-16 23:25:59 +04:00
}
}
lua_pushstring(L, luaT_eventname[event]);
luaD_callTM(L, im, 3, 1);
1997-09-16 23:25:59 +04:00
}
1999-12-01 22:50:08 +03:00
static void call_arith (lua_State *L, StkId top, IMS event) {
call_binTM(L, top, event, "unexpected type in arithmetic operation");
1997-09-16 23:25:59 +04:00
}
1999-08-17 00:52:00 +04:00
static int luaV_strcomp (const char *l, long ll, const char *r, long lr) {
1998-03-06 19:54:42 +03:00
for (;;) {
long temp = strcoll(l, r);
if (temp != 0) return temp;
/* strings are equal up to a '\0' */
temp = strlen(l); /* index of first '\0' in both strings */
if (temp == ll) /* l is finished? */
return (temp == lr) ? 0 : -1; /* l is equal or smaller than r */
else if (temp == lr) /* r is finished? */
return 1; /* l is greater than r (because l is not finished) */
/* both strings longer than temp; go on comparing (after the '\0') */
temp++;
l += temp; ll -= temp; r += temp; lr -= temp;
}
}
1999-12-01 22:50:08 +03:00
void luaV_comparison (lua_State *L, StkId top, lua_Type ttype_less,
lua_Type ttype_equal, lua_Type ttype_great, IMS op) {
const TObject *l = top-2;
const TObject *r = top-1;
1999-01-20 23:22:06 +03:00
real result;
1997-09-16 23:25:59 +04:00
if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
1999-01-20 23:22:06 +03:00
result = nvalue(l)-nvalue(r);
1997-09-16 23:25:59 +04:00
else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
1999-01-20 23:22:06 +03:00
result = luaV_strcomp(svalue(l), tsvalue(l)->u.s.len,
svalue(r), tsvalue(r)->u.s.len);
1997-09-16 23:25:59 +04:00
else {
1999-12-01 22:50:08 +03:00
call_binTM(L, top, op, "unexpected type in comparison");
1997-09-16 23:25:59 +04:00
return;
}
1999-12-01 22:50:08 +03:00
nvalue(top-2) = 1;
ttype(top-2) = (result < 0) ? ttype_less :
1997-09-16 23:25:59 +04:00
(result == 0) ? ttype_equal : ttype_great;
}
1999-12-01 22:50:08 +03:00
void luaV_pack (lua_State *L, StkId firstelem, int nvararg, TObject *tab) {
1997-09-16 23:25:59 +04:00
int i;
Hash *htab;
1999-12-01 22:50:08 +03:00
htab = avalue(tab) = luaH_new(L, nvararg+1); /* +1 for field `n' */
1997-09-16 23:25:59 +04:00
ttype(tab) = LUA_T_ARRAY;
for (i=0; i<nvararg; i++)
luaH_setint(L, htab, i+1, firstelem+i);
1999-12-01 22:50:08 +03:00
luaV_setn(L, htab, nvararg); /* store counter in field `n' */
1997-09-16 23:25:59 +04:00
}
1999-12-01 22:50:08 +03:00
static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
1997-09-16 23:25:59 +04:00
TObject arg;
1999-12-01 22:50:08 +03:00
int nvararg = (L->top-base) - nfixargs;
if (nvararg < 0) {
luaV_pack(L, base, 0, &arg);
luaD_adjusttop(L, base, nfixargs);
}
else {
luaV_pack(L, base+nfixargs, nvararg, &arg);
L->top = base+nfixargs;
}
*L->top++ = arg;
1997-09-16 23:25:59 +04:00
}
/*
1999-12-09 23:01:48 +03:00
** Executes the given Lua function. Parameters are between [base,top).
** Returns n such that the the results are between [n,top).
1997-09-16 23:25:59 +04:00
*/
1999-11-30 16:06:50 +03:00
StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
StkId base) {
1999-12-01 22:50:08 +03:00
register StkId top; /* keep top local, for performance */
1999-08-17 00:52:00 +04:00
register const Byte *pc = tf->code;
const TObject *consts = tf->consts;
luaD_checkstack(L, (*pc++)+EXTRA_STACK);
1998-01-12 16:35:37 +03:00
if (*pc < ZEROVARARG)
1999-12-01 22:50:08 +03:00
luaD_adjusttop(L, base, *(pc++));
1998-01-12 16:35:37 +03:00
else { /* varargs */
1999-12-01 22:50:08 +03:00
adjust_varargs(L, base, (*pc++)-ZEROVARARG);
luaC_checkGC(L);
1998-01-12 16:35:37 +03:00
}
1999-12-01 22:50:08 +03:00
top = L->top;
1998-12-03 18:45:15 +03:00
for (;;) {
register int aux = 0;
switchentry:
switch ((OpCode)*pc++) {
1997-09-16 23:25:59 +04:00
1999-03-06 00:16:07 +03:00
case ENDCODE:
return L->top; /* no results */
1999-12-09 23:01:48 +03:00
case RETCODE:
L->top = top;
return base+(*pc++);
1999-03-06 00:16:07 +03:00
case CALL: aux = *pc++;
1999-12-01 22:50:08 +03:00
L->top = top;
luaD_call(L, base+(*pc++), aux);
top = L->top;
1999-03-06 00:16:07 +03:00
break;
case TAILCALL: aux = *pc++;
1999-12-01 22:50:08 +03:00
L->top = top;
luaD_call(L, base+(*pc++), MULT_RET);
return base+aux;
case PUSHNIL: aux = *pc++;
do {
1999-12-01 22:50:08 +03:00
ttype(top++) = LUA_T_NIL;
} while (aux--);
1997-09-16 23:25:59 +04:00
break;
case POP: aux = *pc++;
1999-12-01 22:50:08 +03:00
top -= aux;
1999-02-08 21:54:19 +03:00
break;
case PUSHNUMBERW: aux += highbyte(L, *pc++);
case PUSHNUMBER: aux += *pc++;
1999-12-01 22:50:08 +03:00
ttype(top) = LUA_T_NUMBER;
nvalue(top) = aux;
top++;
1999-02-09 18:59:10 +03:00
break;
case PUSHNUMBERNEGW: aux += highbyte(L, *pc++);
1999-02-09 21:01:55 +03:00
case PUSHNUMBERNEG: aux += *pc++;
1999-12-01 22:50:08 +03:00
ttype(top) = LUA_T_NUMBER;
nvalue(top) = -aux;
top++;
1997-09-16 23:25:59 +04:00
break;
case PUSHCONSTANTW: aux += highbyte(L, *pc++);
case PUSHCONSTANT: aux += *pc++;
1999-12-01 22:50:08 +03:00
*top++ = consts[aux];
break;
case PUSHUPVALUE: aux = *pc++;
1999-12-01 22:50:08 +03:00
*top++ = cl->consts[aux+1];
break;
case PUSHLOCAL: aux = *pc++;
1999-12-01 22:50:08 +03:00
*top++ = *(base+aux);
1997-09-16 23:25:59 +04:00
break;
case GETGLOBALW: aux += highbyte(L, *pc++);
case GETGLOBAL: aux += *pc++;
1999-12-01 22:50:08 +03:00
L->top = top;
luaV_getglobal(L, tsvalue(&consts[aux])->u.s.gv);
1999-12-01 22:50:08 +03:00
top++;
1997-09-16 23:25:59 +04:00
break;
1997-09-19 22:40:32 +04:00
case GETTABLE:
1999-12-01 22:50:08 +03:00
L->top = top;
luaV_gettable(L);
1999-12-01 22:50:08 +03:00
top--;
break;
1997-09-16 23:25:59 +04:00
case GETDOTTEDW: aux += highbyte(L, *pc++);
case GETDOTTED: aux += *pc++;
1999-12-01 22:50:08 +03:00
*top++ = consts[aux];
L->top = top;
luaV_gettable(L);
1999-12-01 22:50:08 +03:00
top--;
break;
case PUSHSELFW: aux += highbyte(L, *pc++);
case PUSHSELF: aux += *pc++; {
TObject receiver;
1999-12-01 22:50:08 +03:00
receiver = *(top-1);
*top++ = consts[aux];
L->top = top;
luaV_gettable(L);
1999-12-01 22:50:08 +03:00
*(top-1) = receiver;
1997-09-16 23:25:59 +04:00
break;
}
case CREATEARRAYW: aux += highbyte(L, *pc++);
case CREATEARRAY: aux += *pc++;
1999-12-01 22:50:08 +03:00
L->top = top;
luaC_checkGC(L);
1999-12-01 22:50:08 +03:00
avalue(top) = luaH_new(L, aux);
ttype(top) = LUA_T_ARRAY;
top++;
1997-09-19 22:40:32 +04:00
break;
case SETLOCAL: aux = *pc++;
1999-12-01 22:50:08 +03:00
*(base+aux) = *(--top);
1997-09-16 23:25:59 +04:00
break;
case SETGLOBALW: aux += highbyte(L, *pc++);
case SETGLOBAL: aux += *pc++;
1999-12-01 22:50:08 +03:00
L->top = top;
luaV_setglobal(L, tsvalue(&consts[aux])->u.s.gv);
1999-12-01 22:50:08 +03:00
top--;
1997-09-16 23:25:59 +04:00
break;
1999-02-08 20:07:59 +03:00
case SETTABLEPOP:
1999-12-01 22:50:08 +03:00
L->top = top;
luaV_settable(L, top-3);
top -= 3; /* pop table, index, and value */
1999-02-08 21:54:19 +03:00
break;
1997-09-16 23:25:59 +04:00
1997-09-19 22:40:32 +04:00
case SETTABLE:
1999-12-01 22:50:08 +03:00
L->top = top;
luaV_settable(L, top-3-(*pc++));
top--; /* pop value */
1997-09-16 23:25:59 +04:00
break;
case SETLISTW: aux += highbyte(L, *pc++);
case SETLIST: aux += *pc++; {
1997-09-19 22:40:32 +04:00
int n = *(pc++);
1999-12-01 22:50:08 +03:00
Hash *arr = avalue(top-n-1);
1999-12-06 14:40:55 +03:00
L->top = top-n; /* final value of `top' (in case of errors) */
aux *= LFIELDS_PER_FLUSH;
1999-01-25 20:39:28 +03:00
for (; n; n--)
1999-12-01 22:50:08 +03:00
luaH_setint(L, arr, n+aux, --top);
1997-09-16 23:25:59 +04:00
break;
}
case SETMAP: aux = *pc++; {
1999-12-06 14:40:55 +03:00
StkId finaltop = top-2*(aux+1);
Hash *arr = avalue(finaltop-1);
L->top = finaltop; /* final value of `top' (in case of errors) */
do {
1999-12-01 22:50:08 +03:00
luaH_set(L, arr, top-2, top-1);
top-=2;
} while (aux--);
1997-09-16 23:25:59 +04:00
break;
}
case NEQOP: aux = 1;
case EQOP: {
1999-12-01 22:50:08 +03:00
int res = luaO_equalObj(top-2, top-1);
if (aux) res = !res;
1999-12-01 22:50:08 +03:00
top--;
ttype(top-1) = res ? LUA_T_NUMBER : LUA_T_NIL;
nvalue(top-1) = 1;
1997-09-16 23:25:59 +04:00
break;
}
case LTOP:
1999-12-01 22:50:08 +03:00
luaV_comparison(L, top, LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT);
top--;
1997-09-16 23:25:59 +04:00
break;
case LEOP:
1999-12-01 22:50:08 +03:00
luaV_comparison(L, top, LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE);
top--;
1997-09-16 23:25:59 +04:00
break;
case GTOP:
1999-12-01 22:50:08 +03:00
luaV_comparison(L, top, LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT);
top--;
1997-09-16 23:25:59 +04:00
break;
case GEOP:
1999-12-01 22:50:08 +03:00
luaV_comparison(L, top, LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE);
top--;
1997-09-16 23:25:59 +04:00
break;
1999-12-01 22:50:08 +03:00
case ADDOP:
if (tonumber(top-1) || tonumber(top-2))
call_arith(L, top, IM_ADD);
else
nvalue(top-2) += nvalue(top-1);
top--;
1997-09-16 23:25:59 +04:00
break;
1999-12-01 22:50:08 +03:00
case SUBOP:
if (tonumber(top-1) || tonumber(top-2))
call_arith(L, top, IM_SUB);
else
nvalue(top-2) -= nvalue(top-1);
top--;
1997-09-16 23:25:59 +04:00
break;
1999-12-01 22:50:08 +03:00
case MULTOP:
if (tonumber(top-1) || tonumber(top-2))
call_arith(L, top, IM_MUL);
else
nvalue(top-2) *= nvalue(top-1);
top--;
1997-09-16 23:25:59 +04:00
break;
1999-12-01 22:50:08 +03:00
case DIVOP:
if (tonumber(top-1) || tonumber(top-2))
call_arith(L, top, IM_DIV);
else
nvalue(top-2) /= nvalue(top-1);
top--;
1997-09-16 23:25:59 +04:00
break;
case POWOP:
1999-12-01 22:50:08 +03:00
call_binTM(L, top, IM_POW, "undefined operation");
top--;
1997-09-16 23:25:59 +04:00
break;
1999-12-01 22:50:08 +03:00
case CONCOP:
if (tostring(L, top-2) || tostring(L, top-1))
call_binTM(L, top, IM_CONCAT, "unexpected type for concatenation");
else
tsvalue(top-2) = strconc(L, tsvalue(top-2), tsvalue(top-1));
1999-12-06 14:40:55 +03:00
top--;
1999-12-01 22:50:08 +03:00
L->top = top;
luaC_checkGC(L);
1997-09-16 23:25:59 +04:00
break;
case MINUSOP:
1999-12-01 22:50:08 +03:00
if (tonumber(top-1)) {
ttype(top) = LUA_T_NIL;
call_arith(L, top+1, IM_UNM);
1997-09-16 23:25:59 +04:00
}
else
1999-12-01 22:50:08 +03:00
nvalue(top-1) = - nvalue(top-1);
1997-09-16 23:25:59 +04:00
break;
case NOTOP:
1999-12-01 22:50:08 +03:00
ttype(top-1) =
(ttype(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL;
nvalue(top-1) = 1;
1997-09-16 23:25:59 +04:00
break;
case ONTJMPW: aux += highbyte(L, *pc++);
case ONTJMP: aux += *pc++;
1999-12-01 22:50:08 +03:00
if (ttype(top-1) != LUA_T_NIL) pc += aux;
else top--;
1997-09-19 22:40:32 +04:00
break;
1997-09-16 23:25:59 +04:00
case ONFJMPW: aux += highbyte(L, *pc++);
case ONFJMP: aux += *pc++;
1999-12-01 22:50:08 +03:00
if (ttype(top-1) == LUA_T_NIL) pc += aux;
else top--;
1997-09-16 23:25:59 +04:00
break;
case JMPW: aux += highbyte(L, *pc++);
case JMP: aux += *pc++;
1997-10-06 18:51:11 +04:00
pc += aux;
1997-09-16 23:25:59 +04:00
break;
case IFFJMPW: aux += highbyte(L, *pc++);
case IFFJMP: aux += *pc++;
1999-12-01 22:50:08 +03:00
if (ttype(--top) == LUA_T_NIL) pc += aux;
break;
case IFTUPJMPW: aux += highbyte(L, *pc++);
case IFTUPJMP: aux += *pc++;
1999-12-01 22:50:08 +03:00
if (ttype(--top) != LUA_T_NIL) pc -= aux;
1997-09-16 23:25:59 +04:00
break;
case IFFUPJMPW: aux += highbyte(L, *pc++);
case IFFUPJMP: aux += *pc++;
1999-12-01 22:50:08 +03:00
if (ttype(--top) == LUA_T_NIL) pc -= aux;
1997-09-16 23:25:59 +04:00
break;
case CLOSUREW: aux += highbyte(L, *pc++);
1999-02-09 18:59:10 +03:00
case CLOSURE: aux += *pc++;
1999-12-01 22:50:08 +03:00
*top++ = consts[aux];
L->top = top;
1999-12-06 14:40:55 +03:00
aux = *pc++; /* number of upvalues */
1999-12-01 22:50:08 +03:00
luaV_closure(L, aux);
luaC_checkGC(L);
1999-12-01 22:50:08 +03:00
top -= aux;
1997-09-16 23:25:59 +04:00
break;
case SETLINEW: aux += highbyte(L, *pc++);
case SETLINE: aux += *pc++;
1999-12-01 22:50:08 +03:00
L->top = top;
if ((base-1)->ttype != LUA_T_LINE) {
1997-09-16 23:25:59 +04:00
/* open space for LINE value */
1999-12-01 22:50:08 +03:00
luaD_openstack(L, base);
base->ttype = LUA_T_LINE;
1997-09-16 23:25:59 +04:00
base++;
1999-12-01 22:50:08 +03:00
top++;
1997-09-16 23:25:59 +04:00
}
1999-12-01 22:50:08 +03:00
(base-1)->value.i = aux;
if (L->linehook)
luaD_lineHook(L, aux);
1997-09-16 23:25:59 +04:00
break;
case LONGARGW: aux += highbyte(L, *pc++);
1999-02-23 16:38:38 +03:00
case LONGARG: aux += *pc++;
aux = highbyte(L, highbyte(L, aux));
goto switchentry; /* do not reset "aux" */
1997-09-16 23:25:59 +04:00
}
}
1997-09-16 23:25:59 +04:00
}