summaryrefslogtreecommitdiff
path: root/src/lvm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lvm.c')
-rw-r--r--src/lvm.c570
1 files changed, 234 insertions, 336 deletions
diff --git a/src/lvm.c b/src/lvm.c
index 72c26c1c..670642b9 100644
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -1,11 +1,14 @@
/*
-** $Id: lvm.c,v 1.30 1998/06/11 18:21:37 roberto Exp $
+** $Id: lvm.c,v 1.58 1999/06/22 20:37:23 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
+#include <ctype.h>
+#include <limits.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "lauxlib.h"
@@ -13,6 +16,7 @@
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
+#include "lobject.h"
#include "lopcodes.h"
#include "lstate.h"
#include "lstring.h"
@@ -27,9 +31,7 @@
#endif
-#define skip_word(pc) (pc+=2)
-#define get_word(pc) ((*(pc)<<8)+(*((pc)+1)))
-#define next_word(pc) (pc+=2, get_word(pc-2))
+#define highbyte(x) ((x)<<8)
/* Extra stack size to run a function: LUA_T_LINE(1), TM calls(2), ... */
@@ -37,45 +39,47 @@
-static TaggedString *strconc (TaggedString *l, TaggedString *r)
-{
- size_t nl = l->u.s.len;
- size_t nr = r->u.s.len;
- char *buffer = luaL_openspace(nl+nr+1);
+static TaggedString *strconc (TaggedString *l, TaggedString *r) {
+ long nl = l->u.s.len;
+ long nr = r->u.s.len;
+ char *buffer = luaL_openspace(nl+nr);
memcpy(buffer, l->str, nl);
memcpy(buffer+nl, r->str, nr);
return luaS_newlstr(buffer, nl+nr);
}
-int luaV_tonumber (TObject *obj)
-{ /* LUA_NUMBER */
- double t;
- char c;
+int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
if (ttype(obj) != LUA_T_STRING)
return 1;
- else if (sscanf(svalue(obj), "%lf %c",&t, &c) == 1) {
- nvalue(obj) = (real)t;
+ else {
+ double t;
+ char *e = svalue(obj);
+ int sig = 1;
+ while (isspace((unsigned char)*e)) e++;
+ if (*e == '-') {
+ e++;
+ sig = -1;
+ }
+ else if (*e == '+') e++;
+ /* no digit before or after decimal point? */
+ if (!isdigit((unsigned char)*e) && !isdigit((unsigned char)*(e+1)))
+ return 2;
+ t = luaO_str2d(e);
+ if (t<0) return 2;
+ nvalue(obj) = (real)t*sig;
ttype(obj) = LUA_T_NUMBER;
return 0;
}
- else
- return 2;
}
-int luaV_tostring (TObject *obj)
-{ /* LUA_NUMBER */
+int luaV_tostring (TObject *obj) { /* LUA_NUMBER */
if (ttype(obj) != LUA_T_NUMBER)
return 1;
else {
- char s[60];
- real f = nvalue(obj);
- int i;
- if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f)
- sprintf (s, "%d", i);
- else
- sprintf (s, NUMBER_FMT, nvalue(obj));
+ char s[32]; /* 16 digits, signal, point and \0 (+ some extra...) */
+ sprintf(s, "%.16g", (double)nvalue(obj));
tsvalue(obj) = luaS_new(s);
ttype(obj) = LUA_T_STRING;
return 0;
@@ -83,8 +87,15 @@ int luaV_tostring (TObject *obj)
}
-void luaV_closure (int nelems)
-{
+void luaV_setn (Hash *t, int val) {
+ TObject index, value;
+ ttype(&index) = LUA_T_STRING; tsvalue(&index) = luaS_new("n");
+ ttype(&value) = LUA_T_NUMBER; nvalue(&value) = val;
+ luaH_set(t, &index, &value);
+}
+
+
+void luaV_closure (int nelems) {
if (nelems > 0) {
struct Stack *S = &L->stack;
Closure *c = luaF_newclosure(nelems);
@@ -101,99 +112,110 @@ void luaV_closure (int nelems)
** Function to index a table.
** Receives the table at top-2 and the index at top-1.
*/
-void luaV_gettable (void)
-{
- struct Stack *S = &L->stack;
+void luaV_gettable (void) {
+ TObject *table = L->stack.top-2;
TObject *im;
- if (ttype(S->top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */
- im = luaT_getimbyObj(S->top-2, IM_GETTABLE);
+ if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */
+ im = luaT_getimbyObj(table, IM_GETTABLE);
+ if (ttype(im) == LUA_T_NIL)
+ lua_error("indexed expression not a table");
+ }
else { /* object is a table... */
- int tg = (S->top-2)->value.a->htag;
+ int tg = table->value.a->htag;
im = luaT_getim(tg, IM_GETTABLE);
if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */
- TObject *h = luaH_get(avalue(S->top-2), S->top-1);
- if (h != NULL && ttype(h) != LUA_T_NIL) {
- --S->top;
- *(S->top-1) = *h;
+ TObject *h = luaH_get(avalue(table), table+1);
+ if (ttype(h) == LUA_T_NIL &&
+ (ttype(im=luaT_getim(tg, IM_INDEX)) != LUA_T_NIL)) {
+ /* result is nil and there is an "index" tag method */
+ luaD_callTM(im, 2, 1); /* calls it */
}
- else if (ttype(im=luaT_getim(tg, IM_INDEX)) != LUA_T_NIL)
- luaD_callTM(im, 2, 1);
else {
- --S->top;
- ttype(S->top-1) = LUA_T_NIL;
+ L->stack.top--;
+ *table = *h; /* "push" result into table position */
}
return;
}
/* else it has a "gettable" method, go through to next command */
}
/* object is not a table, or it has a "gettable" method */
- if (ttype(im) != LUA_T_NIL)
- luaD_callTM(im, 2, 1);
- else
- lua_error("indexed expression not a table");
+ luaD_callTM(im, 2, 1);
}
/*
-** Function to store indexed based on values at the stack.top
-** mode = 0: raw store (without tag methods)
-** mode = 1: normal store (with tag methods)
-** mode = 2: "deep L->stack.stack" store (with tag methods)
+** Receives table at *t, index at *(t+1) and value at top.
*/
-void luaV_settable (TObject *t, int mode)
-{
+void luaV_settable (TObject *t) {
struct Stack *S = &L->stack;
- TObject *im = (mode == 0) ? NULL : luaT_getimbyObj(t, IM_SETTABLE);
- if (ttype(t) == LUA_T_ARRAY && (im == NULL || ttype(im) == LUA_T_NIL)) {
- TObject *h = luaH_set(avalue(t), t+1);
- *h = *(S->top-1);
- S->top -= (mode == 2) ? 1 : 3;
+ TObject *im;
+ if (ttype(t) != LUA_T_ARRAY) { /* not a table, get "settable" method */
+ im = luaT_getimbyObj(t, IM_SETTABLE);
+ if (ttype(im) == LUA_T_NIL)
+ lua_error("indexed expression not a table");
}
- else { /* object is not a table, and/or has a specific "settable" method */
- if (im && ttype(im) != LUA_T_NIL) {
- if (mode == 2) {
- *(S->top+1) = *(L->stack.top-1);
- *(S->top) = *(t+1);
- *(S->top-1) = *t;
- S->top += 2; /* WARNING: caller must assure stack space */
- }
- luaD_callTM(im, 3, 0);
+ else { /* object is a table... */
+ im = luaT_getim(avalue(t)->htag, IM_SETTABLE);
+ if (ttype(im) == LUA_T_NIL) { /* and does not have a "settable" method */
+ luaH_set(avalue(t), t+1, S->top-1);
+ S->top--; /* pop value */
+ return;
}
- else
- lua_error("indexed expression not a table");
+ /* else it has a "settable" method, go through to next command */
}
+ /* object is not a table, or it has a "settable" method */
+ /* prepare arguments and call the tag method */
+ *(S->top+1) = *(L->stack.top-1);
+ *(S->top) = *(t+1);
+ *(S->top-1) = *t;
+ S->top += 2; /* WARNING: caller must assure stack space */
+ luaD_callTM(im, 3, 0);
}
-void luaV_getglobal (TaggedString *ts)
-{
- /* WARNING: caller must assure stack space */
- TObject *value = &ts->u.s.globalval;
- TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL);
- if (ttype(im) == LUA_T_NIL) { /* default behavior */
- *L->stack.top++ = *value;
- }
+void luaV_rawsettable (TObject *t) {
+ if (ttype(t) != LUA_T_ARRAY)
+ lua_error("indexed expression not a table");
else {
struct Stack *S = &L->stack;
- ttype(S->top) = LUA_T_STRING;
- tsvalue(S->top) = ts;
- S->top++;
- *S->top++ = *value;
- luaD_callTM(im, 2, 1);
+ luaH_set(avalue(t), t+1, S->top-1);
+ S->top -= 3;
}
}
-void luaV_setglobal (TaggedString *ts)
-{
+void luaV_getglobal (TaggedString *ts) {
+ /* WARNING: caller must assure stack space */
+ /* only userdata, tables and nil can have getglobal tag methods */
+ static char valid_getglobals[] = {1, 0, 0, 1, 0, 0, 1, 0}; /* ORDER LUA_T */
+ TObject *value = &ts->u.s.globalval;
+ if (valid_getglobals[-ttype(value)]) {
+ TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL);
+ if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */
+ struct Stack *S = &L->stack;
+ ttype(S->top) = LUA_T_STRING;
+ tsvalue(S->top) = ts;
+ S->top++;
+ *S->top++ = *value;
+ luaD_callTM(im, 2, 1);
+ return;
+ }
+ /* else no tag method: go through to default behavior */
+ }
+ *L->stack.top++ = *value; /* default behavior */
+}
+
+
+void luaV_setglobal (TaggedString *ts) {
TObject *oldvalue = &ts->u.s.globalval;
TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL);
- if (ttype(im) == LUA_T_NIL) /* default behavior */
+ if (ttype(im) == LUA_T_NIL) /* is there a tag method? */
luaS_rawsetglobal(ts, --L->stack.top);
else {
/* WARNING: caller must assure stack space */
struct Stack *S = &L->stack;
- TObject newvalue = *(S->top-1);
+ TObject newvalue;
+ newvalue = *(S->top-1);
ttype(S->top-1) = LUA_T_STRING;
tsvalue(S->top-1) = ts;
*S->top++ = *oldvalue;
@@ -225,7 +247,7 @@ static void call_arith (IMS event)
}
-static int strcomp (char *l, long ll, char *r, long lr)
+static int luaV_strcomp (char *l, long ll, char *r, long lr)
{
for (;;) {
long temp = strcoll(l, r);
@@ -242,18 +264,17 @@ static int strcomp (char *l, long ll, char *r, long lr)
}
}
-static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
- lua_Type ttype_great, IMS op)
-{
+void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal,
+ lua_Type ttype_great, IMS op) {
struct Stack *S = &L->stack;
TObject *l = S->top-2;
TObject *r = S->top-1;
- int result;
+ real result;
if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
- result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1;
+ result = nvalue(l)-nvalue(r);
else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
- result = strcomp(svalue(l), tsvalue(l)->u.s.len,
- svalue(r), tsvalue(r)->u.s.len);
+ result = luaV_strcomp(svalue(l), tsvalue(l)->u.s.len,
+ svalue(r), tsvalue(r)->u.s.len);
else {
call_binTM(op, "unexpected type in comparison");
return;
@@ -265,27 +286,16 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
}
-void luaV_pack (StkId firstel, int nvararg, TObject *tab)
-{
+void luaV_pack (StkId firstel, int nvararg, TObject *tab) {
TObject *firstelem = L->stack.stack+firstel;
int i;
+ Hash *htab;
if (nvararg < 0) nvararg = 0;
- avalue(tab) = luaH_new(nvararg+1); /* +1 for field 'n' */
+ htab = avalue(tab) = luaH_new(nvararg+1); /* +1 for field 'n' */
ttype(tab) = LUA_T_ARRAY;
- for (i=0; i<nvararg; i++) {
- TObject index;
- ttype(&index) = LUA_T_NUMBER;
- nvalue(&index) = i+1;
- *(luaH_set(avalue(tab), &index)) = *(firstelem+i);
- }
- /* store counter in field "n" */ {
- TObject index, extra;
- ttype(&index) = LUA_T_STRING;
- tsvalue(&index) = luaS_new("n");
- ttype(&extra) = LUA_T_NUMBER;
- nvalue(&extra) = nvararg;
- *(luaH_set(avalue(tab), &index)) = extra;
- }
+ for (i=0; i<nvararg; i++)
+ luaH_setint(htab, i+1, firstelem+i);
+ luaV_setn(htab, nvararg); /* store counter in field "n" */
}
@@ -305,12 +315,11 @@ static void adjust_varargs (StkId first_extra_arg)
** [stack+base,top). Returns n such that the the results are between
** [stack+n,top).
*/
-StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base)
-{
+StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
struct Stack *S = &L->stack; /* to optimize */
- Byte *pc = tf->code;
+ register Byte *pc = tf->code;
TObject *consts = tf->consts;
- if (lua_callhook)
+ if (L->callhook)
luaD_callHook(base, tf, 0);
luaD_checkstack((*pc++)+EXTRA_STACK);
if (*pc < ZEROVARARG)
@@ -319,228 +328,159 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base)
luaC_checkGC();
adjust_varargs(base+(*pc++)-ZEROVARARG);
}
- while (1) {
- int aux;
- switch ((OpCode)(aux = *pc++)) {
+ for (;;) {
+ register int aux = 0;
+ switchentry:
+ switch ((OpCode)*pc++) {
+
+ case ENDCODE:
+ S->top = S->stack + base;
+ goto ret;
+
+ case RETCODE:
+ base += *pc++;
+ goto ret;
- case PUSHNIL0:
- ttype(S->top++) = LUA_T_NIL;
+ case CALL: aux = *pc++;
+ luaD_calln(*pc++, aux);
break;
- case PUSHNIL:
- aux = *pc++;
+ case TAILCALL: aux = *pc++;
+ luaD_calln(*pc++, MULT_RET);
+ base += aux;
+ goto ret;
+
+ case PUSHNIL: aux = *pc++;
do {
ttype(S->top++) = LUA_T_NIL;
} while (aux--);
break;
- case PUSHNUMBER:
- aux = *pc++; goto pushnumber;
-
- case PUSHNUMBERW:
- aux = next_word(pc); goto pushnumber;
+ case POP: aux = *pc++;
+ S->top -= aux;
+ break;
- case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2:
- aux -= PUSHNUMBER0;
- pushnumber:
+ case PUSHNUMBERW: aux += highbyte(*pc++);
+ case PUSHNUMBER: aux += *pc++;
ttype(S->top) = LUA_T_NUMBER;
nvalue(S->top) = aux;
S->top++;
break;
- case PUSHLOCAL:
- aux = *pc++; goto pushlocal;
+ case PUSHNUMBERNEGW: aux += highbyte(*pc++);
+ case PUSHNUMBERNEG: aux += *pc++;
+ ttype(S->top) = LUA_T_NUMBER;
+ nvalue(S->top) = -aux;
+ S->top++;
+ break;
- case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3:
- case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7:
- aux -= PUSHLOCAL0;
- pushlocal:
- *S->top++ = *((S->stack+base) + aux);
+ case PUSHCONSTANTW: aux += highbyte(*pc++);
+ case PUSHCONSTANT: aux += *pc++;
+ *S->top++ = consts[aux];
break;
- case GETGLOBALW:
- aux = next_word(pc); goto getglobal;
+ case PUSHUPVALUE: aux = *pc++;
+ *S->top++ = cl->consts[aux+1];
+ break;
- case GETGLOBAL:
- aux = *pc++; goto getglobal;
+ case PUSHLOCAL: aux = *pc++;
+ *S->top++ = *((S->stack+base) + aux);
+ break;
- case GETGLOBAL0: case GETGLOBAL1: case GETGLOBAL2: case GETGLOBAL3:
- case GETGLOBAL4: case GETGLOBAL5: case GETGLOBAL6: case GETGLOBAL7:
- aux -= GETGLOBAL0;
- getglobal:
+ case GETGLOBALW: aux += highbyte(*pc++);
+ case GETGLOBAL: aux += *pc++;
luaV_getglobal(tsvalue(&consts[aux]));
break;
case GETTABLE:
- luaV_gettable();
- break;
-
- case GETDOTTEDW:
- aux = next_word(pc); goto getdotted;
-
- case GETDOTTED:
- aux = *pc++; goto getdotted;
+ luaV_gettable();
+ break;
- case GETDOTTED0: case GETDOTTED1: case GETDOTTED2: case GETDOTTED3:
- case GETDOTTED4: case GETDOTTED5: case GETDOTTED6: case GETDOTTED7:
- aux -= GETDOTTED0;
- getdotted:
+ case GETDOTTEDW: aux += highbyte(*pc++);
+ case GETDOTTED: aux += *pc++;
*S->top++ = consts[aux];
luaV_gettable();
break;
- case PUSHSELFW:
- aux = next_word(pc); goto pushself;
-
- case PUSHSELF:
- aux = *pc++; goto pushself;
-
- case PUSHSELF0: case PUSHSELF1: case PUSHSELF2: case PUSHSELF3:
- case PUSHSELF4: case PUSHSELF5: case PUSHSELF6: case PUSHSELF7:
- aux -= PUSHSELF0;
- pushself: {
- TObject receiver = *(S->top-1);
+ case PUSHSELFW: aux += highbyte(*pc++);
+ case PUSHSELF: aux += *pc++; {
+ TObject receiver;
+ receiver = *(S->top-1);
*S->top++ = consts[aux];
luaV_gettable();
*S->top++ = receiver;
break;
}
- case PUSHCONSTANTW:
- aux = next_word(pc); goto pushconstant;
-
- case PUSHCONSTANT:
- aux = *pc++; goto pushconstant;
-
- case PUSHCONSTANT0: case PUSHCONSTANT1: case PUSHCONSTANT2:
- case PUSHCONSTANT3: case PUSHCONSTANT4: case PUSHCONSTANT5:
- case PUSHCONSTANT6: case PUSHCONSTANT7:
- aux -= PUSHCONSTANT0;
- pushconstant:
- *S->top++ = consts[aux];
- break;
-
- case PUSHUPVALUE:
- aux = *pc++; goto pushupvalue;
-
- case PUSHUPVALUE0: case PUSHUPVALUE1:
- aux -= PUSHUPVALUE0;
- pushupvalue:
- *S->top++ = cl->consts[aux+1];
+ case CREATEARRAYW: aux += highbyte(*pc++);
+ case CREATEARRAY: aux += *pc++;
+ luaC_checkGC();
+ avalue(S->top) = luaH_new(aux);
+ ttype(S->top) = LUA_T_ARRAY;
+ S->top++;
break;
- case SETLOCAL:
- aux = *pc++; goto setlocal;
-
- case SETLOCAL0: case SETLOCAL1: case SETLOCAL2: case SETLOCAL3:
- case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7:
- aux -= SETLOCAL0;
- setlocal:
+ case SETLOCAL: aux = *pc++;
*((S->stack+base) + aux) = *(--S->top);
break;
- case SETGLOBALW:
- aux = next_word(pc); goto setglobal;
-
- case SETGLOBAL:
- aux = *pc++; goto setglobal;
-
- case SETGLOBAL0: case SETGLOBAL1: case SETGLOBAL2: case SETGLOBAL3:
- case SETGLOBAL4: case SETGLOBAL5: case SETGLOBAL6: case SETGLOBAL7:
- aux -= SETGLOBAL0;
- setglobal:
+ case SETGLOBALW: aux += highbyte(*pc++);
+ case SETGLOBAL: aux += *pc++;
luaV_setglobal(tsvalue(&consts[aux]));
break;
- case SETTABLE0:
- luaV_settable(S->top-3, 1);
- break;
+ case SETTABLEPOP:
+ luaV_settable(S->top-3);
+ S->top -= 2; /* pop table and index */
+ break;
case SETTABLE:
- luaV_settable(S->top-3-(*pc++), 2);
+ luaV_settable(S->top-3-(*pc++));
break;
- case SETLISTW:
- aux = next_word(pc); aux *= LFIELDS_PER_FLUSH; goto setlist;
-
- case SETLIST:
- aux = *(pc++) * LFIELDS_PER_FLUSH; goto setlist;
-
- case SETLIST0:
- aux = 0;
- setlist: {
+ case SETLISTW: aux += highbyte(*pc++);
+ case SETLIST: aux += *pc++; {
int n = *(pc++);
- TObject *arr = S->top-n-1;
- for (; n; n--) {
- ttype(S->top) = LUA_T_NUMBER;
- nvalue(S->top) = n+aux;
- *(luaH_set(avalue(arr), S->top)) = *(S->top-1);
- S->top--;
- }
+ Hash *arr = avalue(S->top-n-1);
+ aux *= LFIELDS_PER_FLUSH;
+ for (; n; n--)
+ luaH_setint(arr, n+aux, --S->top);
break;
}
- case SETMAP0:
- aux = 0; goto setmap;
-
- case SETMAP:
- aux = *pc++;
- setmap: {
- TObject *arr = S->top-(2*aux)-3;
+ case SETMAP: aux = *pc++; {
+ Hash *arr = avalue(S->top-(2*aux)-3);
do {
- *(luaH_set(avalue(arr), S->top-2)) = *(S->top-1);
+ luaH_set(arr, S->top-2, S->top-1);
S->top-=2;
} while (aux--);
break;
}
- case POP:
- aux = *pc++; goto pop;
-
- case POP0: case POP1:
- aux -= POP0;
- pop:
- S->top -= (aux+1);
- break;
-
- case CREATEARRAYW:
- aux = next_word(pc); goto createarray;
-
- case CREATEARRAY0: case CREATEARRAY1:
- aux -= CREATEARRAY0; goto createarray;
-
- case CREATEARRAY:
- aux = *pc++;
- createarray:
- luaC_checkGC();
- avalue(S->top) = luaH_new(aux);
- ttype(S->top) = LUA_T_ARRAY;
- S->top++;
- break;
-
- case EQOP: case NEQOP: {
+ case NEQOP: aux = 1;
+ case EQOP: {
int res = luaO_equalObj(S->top-2, S->top-1);
+ if (aux) res = !res;
S->top--;
- if (aux == NEQOP) res = !res;
ttype(S->top-1) = res ? LUA_T_NUMBER : LUA_T_NIL;
nvalue(S->top-1) = 1;
break;
}
case LTOP:
- comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT);
+ luaV_comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT);
break;
case LEOP:
- comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE);
+ luaV_comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE);
break;
case GTOP:
- comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT);
+ luaV_comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT);
break;
case GEOP:
- comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE);
+ luaV_comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE);
break;
case ADDOP: {
@@ -624,98 +564,47 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base)
nvalue(S->top-1) = 1;
break;
- case ONTJMPW:
- aux = next_word(pc); goto ontjmp;
-
- case ONTJMP:
- aux = *pc++;
- ontjmp:
+ case ONTJMPW: aux += highbyte(*pc++);
+ case ONTJMP: aux += *pc++;
if (ttype(S->top-1) != LUA_T_NIL) pc += aux;
else S->top--;
break;
- case ONFJMPW:
- aux = next_word(pc); goto onfjmp;
-
- case ONFJMP:
- aux = *pc++;
- onfjmp:
+ case ONFJMPW: aux += highbyte(*pc++);
+ case ONFJMP: aux += *pc++;
if (ttype(S->top-1) == LUA_T_NIL) pc += aux;
else S->top--;
break;
- case JMPW:
- aux = next_word(pc); goto jmp;
-
- case JMP:
- aux = *pc++;
- jmp:
+ case JMPW: aux += highbyte(*pc++);
+ case JMP: aux += *pc++;
pc += aux;
break;
- case IFFJMPW:
- aux = next_word(pc); goto iffjmp;
-
- case IFFJMP:
- aux = *pc++;
- iffjmp:
+ case IFFJMPW: aux += highbyte(*pc++);
+ case IFFJMP: aux += *pc++;
if (ttype(--S->top) == LUA_T_NIL) pc += aux;
break;
- case IFTUPJMPW:
- aux = next_word(pc); goto iftupjmp;
-
- case IFTUPJMP:
- aux = *pc++;
- iftupjmp:
+ case IFTUPJMPW: aux += highbyte(*pc++);
+ case IFTUPJMP: aux += *pc++;
if (ttype(--S->top) != LUA_T_NIL) pc -= aux;
break;
- case IFFUPJMPW:
- aux = next_word(pc); goto iffupjmp;
-
- case IFFUPJMP:
- aux = *pc++;
- iffupjmp:
+ case IFFUPJMPW: aux += highbyte(*pc++);
+ case IFFUPJMP: aux += *pc++;
if (ttype(--S->top) == LUA_T_NIL) pc -= aux;
break;
- case CLOSUREW:
- aux = next_word(pc); goto closure;
-
- case CLOSURE:
- aux = *pc++;
- closure:
+ case CLOSUREW: aux += highbyte(*pc++);
+ case CLOSURE: aux += *pc++;
*S->top++ = consts[aux];
luaV_closure(*pc++);
luaC_checkGC();
break;
- case CALLFUNC:
- aux = *pc++; goto callfunc;
-
- case CALLFUNC0: case CALLFUNC1:
- aux -= CALLFUNC0;
- callfunc: {
- StkId newBase = (S->top-S->stack)-(*pc++);
- luaD_call(newBase, aux);
- break;
- }
-
- case ENDCODE:
- S->top = S->stack + base;
- /* goes through */
- case RETCODE:
- if (lua_callhook)
- luaD_callHook(base, NULL, 1);
- return (base + ((aux==RETCODE) ? *pc : 0));
-
- case SETLINEW:
- aux = next_word(pc); goto setline;
-
- case SETLINE:
- aux = *pc++;
- setline:
+ case SETLINEW: aux += highbyte(*pc++);
+ case SETLINE: aux += *pc++;
if ((S->stack+base-1)->ttype != LUA_T_LINE) {
/* open space for LINE value */
luaD_openstack((S->top-S->stack)-base);
@@ -723,15 +612,24 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base)
(S->stack+base-1)->ttype = LUA_T_LINE;
}
(S->stack+base-1)->value.i = aux;
- if (lua_linehook)
+ if (L->linehook)
luaD_lineHook(aux);
break;
-#ifdef DEBUG
- default:
- LUA_INTERNALERROR("opcode doesn't match");
-#endif
+ case LONGARGW: aux += highbyte(*pc++);
+ case LONGARG: aux += *pc++;
+ aux = highbyte(highbyte(aux));
+ goto switchentry; /* do not reset "aux" */
+
+ case CHECKSTACK: aux = *pc++;
+ LUA_ASSERT((S->top-S->stack)-base == aux && S->last >= S->top,
+ "wrong stack size");
+ break;
+
}
- }
+ } ret:
+ if (L->callhook)
+ luaD_callHook(0, NULL, 1);
+ return base;
}