some name changes

This commit is contained in:
Roberto Ierusalimschy
2000-03-10 15:37:44 -03:00
parent 3d0577f4b9
commit 73aa465a8e
30 changed files with 632 additions and 631 deletions

54
lapi.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 1.72 2000/02/22 17:54:16 roberto Exp roberto $ ** $Id: lapi.c,v 1.73 2000/03/03 14:58:26 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -33,7 +33,7 @@ const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
const TObject *luaA_protovalue (const TObject *o) { const TObject *luaA_protovalue (const TObject *o) {
switch (ttype(o)) { switch (ttype(o)) {
case LUA_T_CCLOSURE: case LUA_T_LCLOSURE: case TAG_CCLOSURE: case TAG_LCLOSURE:
return protovalue(o); return protovalue(o);
default: default:
return o; return o;
@@ -106,7 +106,7 @@ lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) {
TObject *method; TObject *method;
luaA_checkCargs(L, 1); luaA_checkCargs(L, 1);
method = L->top-1; method = L->top-1;
if ((ttype(method) != LUA_T_NIL) && (*lua_type(L, method) != 'f')) if ((ttype(method) != TAG_NIL) && (*lua_type(L, method) != 'f'))
lua_error(L, "Lua API error - tag method must be a function or nil"); lua_error(L, "Lua API error - tag method must be a function or nil");
luaT_settagmethod(L, tag, event, method); luaT_settagmethod(L, tag, event, method);
return luaA_putObjectOnTop(L); return luaA_putObjectOnTop(L);
@@ -132,7 +132,7 @@ lua_Object lua_gettable (lua_State *L) {
lua_Object lua_rawgettable (lua_State *L) { lua_Object lua_rawgettable (lua_State *L) {
lua_Object res; lua_Object res;
luaA_checkCargs(L, 2); luaA_checkCargs(L, 2);
if (ttype(L->top-2) != LUA_T_ARRAY) if (ttype(L->top-2) != TAG_ARRAY)
lua_error(L, "indexed expression not a table in rawgettable"); lua_error(L, "indexed expression not a table in rawgettable");
res = luaA_putluaObject(L, luaH_get(L, avalue(L->top-2), L->top-1)); res = luaA_putluaObject(L, luaH_get(L, avalue(L->top-2), L->top-1));
L->top -= 2; L->top -= 2;
@@ -159,7 +159,7 @@ lua_Object lua_createtable (lua_State *L) {
TObject o; TObject o;
luaC_checkGC(L); luaC_checkGC(L);
avalue(&o) = luaH_new(L, 0); avalue(&o) = luaH_new(L, 0);
ttype(&o) = LUA_T_ARRAY; ttype(&o) = TAG_ARRAY;
return luaA_putluaObject(L, &o); return luaA_putluaObject(L, &o);
} }
@@ -196,21 +196,21 @@ const char *lua_type (lua_State *L, lua_Object o) {
int lua_isnil (lua_State *L, lua_Object o) { int lua_isnil (lua_State *L, lua_Object o) {
UNUSED(L); UNUSED(L);
return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_NIL); return (o != LUA_NOOBJECT) && (ttype(o) == TAG_NIL);
} }
int lua_istable (lua_State *L, lua_Object o) { int lua_istable (lua_State *L, lua_Object o) {
UNUSED(L); UNUSED(L);
return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_ARRAY); return (o != LUA_NOOBJECT) && (ttype(o) == TAG_ARRAY);
} }
int lua_isuserdata (lua_State *L, lua_Object o) { int lua_isuserdata (lua_State *L, lua_Object o) {
UNUSED(L); UNUSED(L);
return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_USERDATA); return (o != LUA_NOOBJECT) && (ttype(o) == TAG_USERDATA);
} }
int lua_iscfunction (lua_State *L, lua_Object o) { int lua_iscfunction (lua_State *L, lua_Object o) {
return (lua_tag(L, o) == LUA_T_CPROTO); return (lua_tag(L, o) == TAG_CPROTO);
} }
int lua_isnumber (lua_State *L, lua_Object o) { int lua_isnumber (lua_State *L, lua_Object o) {
@@ -220,8 +220,8 @@ int lua_isnumber (lua_State *L, lua_Object o) {
int lua_isstring (lua_State *L, lua_Object o) { int lua_isstring (lua_State *L, lua_Object o) {
UNUSED(L); UNUSED(L);
return (o != LUA_NOOBJECT && (ttype(o) == LUA_T_STRING || return (o != LUA_NOOBJECT && (ttype(o) == TAG_STRING ||
ttype(o) == LUA_T_NUMBER)); ttype(o) == TAG_NUMBER));
} }
int lua_isfunction (lua_State *L, lua_Object o) { int lua_isfunction (lua_State *L, lua_Object o) {
@@ -258,7 +258,7 @@ long lua_strlen (lua_State *L, lua_Object obj) {
void *lua_getuserdata (lua_State *L, lua_Object obj) { void *lua_getuserdata (lua_State *L, lua_Object obj) {
UNUSED(L); UNUSED(L);
if (obj == LUA_NOOBJECT || ttype(obj) != LUA_T_USERDATA) if (obj == LUA_NOOBJECT || ttype(obj) != TAG_USERDATA)
return NULL; return NULL;
else return tsvalue(obj)->u.d.value; else return tsvalue(obj)->u.d.value;
} }
@@ -271,19 +271,19 @@ lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj) {
void lua_pushnil (lua_State *L) { void lua_pushnil (lua_State *L) {
ttype(L->top) = LUA_T_NIL; ttype(L->top) = TAG_NIL;
incr_top; incr_top;
} }
void lua_pushnumber (lua_State *L, double n) { void lua_pushnumber (lua_State *L, double n) {
ttype(L->top) = LUA_T_NUMBER; ttype(L->top) = TAG_NUMBER;
nvalue(L->top) = n; nvalue(L->top) = n;
incr_top; incr_top;
} }
void lua_pushlstring (lua_State *L, const char *s, long len) { void lua_pushlstring (lua_State *L, const char *s, long len) {
tsvalue(L->top) = luaS_newlstr(L, s, len); tsvalue(L->top) = luaS_newlstr(L, s, len);
ttype(L->top) = LUA_T_STRING; ttype(L->top) = TAG_STRING;
incr_top; incr_top;
luaC_checkGC(L); luaC_checkGC(L);
} }
@@ -299,7 +299,7 @@ void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
if (fn == NULL) if (fn == NULL)
lua_error(L, "Lua API error - attempt to push a NULL Cfunction"); lua_error(L, "Lua API error - attempt to push a NULL Cfunction");
luaA_checkCargs(L, n); luaA_checkCargs(L, n);
ttype(L->top) = LUA_T_CPROTO; ttype(L->top) = TAG_CPROTO;
fvalue(L->top) = fn; fvalue(L->top) = fn;
incr_top; incr_top;
luaV_closure(L, n); luaV_closure(L, n);
@@ -310,7 +310,7 @@ void lua_pushusertag (lua_State *L, void *u, int tag) {
if (tag < 0 && tag != LUA_ANYTAG) if (tag < 0 && tag != LUA_ANYTAG)
luaT_realtag(L, tag); /* error if tag is not valid */ luaT_realtag(L, tag); /* error if tag is not valid */
tsvalue(L->top) = luaS_createudata(L, u, tag); tsvalue(L->top) = luaS_createudata(L, u, tag);
ttype(L->top) = LUA_T_USERDATA; ttype(L->top) = TAG_USERDATA;
incr_top; incr_top;
luaC_checkGC(L); luaC_checkGC(L);
} }
@@ -331,8 +331,8 @@ void lua_pushobject (lua_State *L, lua_Object o) {
int lua_tag (lua_State *L, lua_Object o) { int lua_tag (lua_State *L, lua_Object o) {
UNUSED(L); UNUSED(L);
if (o == LUA_NOOBJECT) if (o == LUA_NOOBJECT)
return LUA_T_NIL; return TAG_NIL;
else if (ttype(o) == LUA_T_USERDATA) /* to allow `old' tags (deprecated) */ else if (ttype(o) == TAG_USERDATA) /* to allow `old' tags (deprecated) */
return o->value.ts->u.d.tag; return o->value.ts->u.d.tag;
else else
return luaT_effectivetag(o); return luaT_effectivetag(o);
@@ -343,10 +343,10 @@ void lua_settag (lua_State *L, int tag) {
luaA_checkCargs(L, 1); luaA_checkCargs(L, 1);
luaT_realtag(L, tag); luaT_realtag(L, tag);
switch (ttype(L->top-1)) { switch (ttype(L->top-1)) {
case LUA_T_ARRAY: case TAG_ARRAY:
(L->top-1)->value.a->htag = tag; (L->top-1)->value.a->htag = tag;
break; break;
case LUA_T_USERDATA: case TAG_USERDATA:
(L->top-1)->value.ts->u.d.tag = tag; (L->top-1)->value.ts->u.d.tag = tag;
break; break;
default: default:
@@ -357,7 +357,7 @@ void lua_settag (lua_State *L, int tag) {
} }
GlobalVar *luaA_nextvar (lua_State *L, TaggedString *ts) { GlobalVar *luaA_nextvar (lua_State *L, TString *ts) {
GlobalVar *gv; GlobalVar *gv;
if (ts == NULL) if (ts == NULL)
gv = L->rootglobal; /* first variable */ gv = L->rootglobal; /* first variable */
@@ -366,10 +366,10 @@ GlobalVar *luaA_nextvar (lua_State *L, TaggedString *ts) {
luaL_arg_check(L, ts->u.s.gv, 1, "variable name expected"); luaL_arg_check(L, ts->u.s.gv, 1, "variable name expected");
gv = ts->u.s.gv->next; /* get next */ gv = ts->u.s.gv->next; /* get next */
} }
while (gv && gv->value.ttype == LUA_T_NIL) /* skip globals with nil */ while (gv && gv->value.ttype == TAG_NIL) /* skip globals with nil */
gv = gv->next; gv = gv->next;
if (gv) { if (gv) {
ttype(L->top) = LUA_T_STRING; tsvalue(L->top) = gv->name; ttype(L->top) = TAG_STRING; tsvalue(L->top) = gv->name;
incr_top; incr_top;
luaA_pushobject(L, &gv->value); luaA_pushobject(L, &gv->value);
} }
@@ -378,7 +378,7 @@ GlobalVar *luaA_nextvar (lua_State *L, TaggedString *ts) {
const char *lua_nextvar (lua_State *L, const char *varname) { const char *lua_nextvar (lua_State *L, const char *varname) {
TaggedString *ts = (varname == NULL) ? NULL : luaS_new(L, varname); TString *ts = (varname == NULL) ? NULL : luaS_new(L, varname);
GlobalVar *gv = luaA_nextvar(L, ts); GlobalVar *gv = luaA_nextvar(L, ts);
if (gv) { if (gv) {
top2LC(L, 2); top2LC(L, 2);
@@ -395,7 +395,7 @@ int luaA_next (lua_State *L, const Hash *t, int i) {
int tsize = t->size; int tsize = t->size;
for (; i<tsize; i++) { for (; i<tsize; i++) {
Node *n = node(t, i); Node *n = node(t, i);
if (ttype(val(n)) != LUA_T_NIL) { if (ttype(val(n)) != TAG_NIL) {
luaA_pushobject(L, key(n)); luaA_pushobject(L, key(n));
luaA_pushobject(L, val(n)); luaA_pushobject(L, val(n));
return i+1; /* index to be used next time */ return i+1; /* index to be used next time */
@@ -406,7 +406,7 @@ int luaA_next (lua_State *L, const Hash *t, int i) {
int lua_next (lua_State *L, lua_Object t, int i) { int lua_next (lua_State *L, lua_Object t, int i) {
if (ttype(t) != LUA_T_ARRAY) if (ttype(t) != TAG_ARRAY)
lua_error(L, "Lua API error - object is not a table in `lua_next'"); lua_error(L, "Lua API error - object is not a table in `lua_next'");
i = luaA_next(L, avalue(t), i); i = luaA_next(L, avalue(t), i);
top2LC(L, (i==0) ? 0 : 2); top2LC(L, (i==0) ? 0 : 2);

4
lapi.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lapi.h,v 1.13 2000/01/19 12:00:45 roberto Exp roberto $ ** $Id: lapi.h,v 1.14 2000/03/03 14:58:26 roberto Exp roberto $
** Auxiliary functions from Lua API ** Auxiliary functions from Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -14,7 +14,7 @@
void luaA_checkCargs (lua_State *L, int nargs); void luaA_checkCargs (lua_State *L, int nargs);
const TObject *luaA_protovalue (const TObject *o); const TObject *luaA_protovalue (const TObject *o);
void luaA_pushobject (lua_State *L, const TObject *o); void luaA_pushobject (lua_State *L, const TObject *o);
GlobalVar *luaA_nextvar (lua_State *L, TaggedString *g); GlobalVar *luaA_nextvar (lua_State *L, TString *g);
int luaA_next (lua_State *L, const Hash *t, int i); int luaA_next (lua_State *L, const Hash *t, int i);
lua_Object luaA_putluaObject (lua_State *L, const TObject *o); lua_Object luaA_putluaObject (lua_State *L, const TObject *o);
lua_Object luaA_putObjectOnTop (lua_State *L); lua_Object luaA_putObjectOnTop (lua_State *L);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lbuiltin.c,v 1.94 2000/03/03 14:58:26 roberto Exp $ ** $Id: lbuiltin.c,v 1.95 2000/03/09 00:19:22 roberto Exp roberto $
** Built-in functions ** Built-in functions
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -52,20 +52,20 @@ void luaB_opentests (lua_State *L);
*/ */
static void pushtagstring (lua_State *L, TaggedString *s) { static void pushtagstring (lua_State *L, TString *s) {
ttype(L->top) = LUA_T_STRING; ttype(L->top) = TAG_STRING;
tsvalue(L->top) = s; tsvalue(L->top) = s;
incr_top; incr_top;
} }
static real getsize (const Hash *h) { static Number getsize (const Hash *h) {
real max = 0; Number max = 0;
int i = h->size; int i = h->size;
Node *n = h->node; Node *n = h->node;
while (i--) { while (i--) {
if (ttype(key(n)) == LUA_T_NUMBER && if (ttype(key(n)) == TAG_NUMBER &&
ttype(val(n)) != LUA_T_NIL && ttype(val(n)) != TAG_NIL &&
nvalue(key(n)) > max) nvalue(key(n)) > max)
max = nvalue(key(n)); max = nvalue(key(n));
n++; n++;
@@ -74,14 +74,14 @@ static real getsize (const Hash *h) {
} }
static real getnarg (lua_State *L, const Hash *a) { static Number getnarg (lua_State *L, const Hash *a) {
TObject index; TObject index;
const TObject *value; const TObject *value;
/* value = table.n */ /* value = table.n */
ttype(&index) = LUA_T_STRING; ttype(&index) = TAG_STRING;
tsvalue(&index) = luaS_new(L, "n"); tsvalue(&index) = luaS_new(L, "n");
value = luaH_get(L, a, &index); value = luaH_get(L, a, &index);
return (ttype(value) == LUA_T_NUMBER) ? nvalue(value) : getsize(a); return (ttype(value) == TAG_NUMBER) ? nvalue(value) : getsize(a);
} }
@@ -167,7 +167,7 @@ void luaB_tonumber (lua_State *L) {
else { else {
const char *s1 = luaL_check_string(L, 1); const char *s1 = luaL_check_string(L, 1);
char *s2; char *s2;
real n; Number n;
luaL_arg_check(L, 0 <= base && base <= 36, 2, "base out of range"); luaL_arg_check(L, 0 <= base && base <= 36, 2, "base out of range");
n = strtoul(s1, &s2, base); n = strtoul(s1, &s2, base);
if (s1 == s2) return; /* no valid digits: return nil */ if (s1 == s2) return; /* no valid digits: return nil */
@@ -244,7 +244,7 @@ void luaB_settagmethod (lua_State *L) {
luaL_arg_check(L, lua_isnil(L, nf) || lua_isfunction(L, nf), 3, luaL_arg_check(L, lua_isnil(L, nf) || lua_isfunction(L, nf), 3,
"function or nil expected"); "function or nil expected");
#ifndef LUA_COMPAT_GC #ifndef LUA_COMPAT_GC
if (strcmp(event, "gc") == 0 && tag != LUA_T_NIL) if (strcmp(event, "gc") == 0 && tag != TAG_NIL)
lua_error(L, "cannot set this `gc' tag method from Lua"); lua_error(L, "cannot set this `gc' tag method from Lua");
#endif #endif
lua_pushobject(L, nf); lua_pushobject(L, nf);
@@ -349,11 +349,11 @@ void luaB_call (lua_State *L) {
void luaB_nextvar (lua_State *L) { void luaB_nextvar (lua_State *L) {
lua_Object o = luaL_nonnullarg(L, 1); lua_Object o = luaL_nonnullarg(L, 1);
TaggedString *name; TString *name;
if (ttype(o) == LUA_T_NIL) if (ttype(o) == TAG_NIL)
name = NULL; name = NULL;
else { else {
luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "variable name expected"); luaL_arg_check(L, ttype(o) == TAG_STRING, 1, "variable name expected");
name = tsvalue(o); name = tsvalue(o);
} }
if (!luaA_nextvar(L, name)) if (!luaA_nextvar(L, name))
@@ -365,7 +365,7 @@ void luaB_next (lua_State *L) {
const Hash *a = gettable(L, 1); const Hash *a = gettable(L, 1);
lua_Object k = luaL_nonnullarg(L, 2); lua_Object k = luaL_nonnullarg(L, 2);
int i; /* `luaA_next' gets first element after `i' */ int i; /* `luaA_next' gets first element after `i' */
if (ttype(k) == LUA_T_NIL) if (ttype(k) == TAG_NIL)
i = 0; /* get first */ i = 0; /* get first */
else { else {
i = luaH_pos(L, a, k)+1; i = luaH_pos(L, a, k)+1;
@@ -380,29 +380,29 @@ void luaB_tostring (lua_State *L) {
lua_Object o = lua_getparam(L, 1); lua_Object o = lua_getparam(L, 1);
char buff[64]; char buff[64];
switch (ttype(o)) { switch (ttype(o)) {
case LUA_T_NUMBER: case TAG_NUMBER:
lua_pushstring(L, lua_getstring(L, o)); lua_pushstring(L, lua_getstring(L, o));
return; return;
case LUA_T_STRING: case TAG_STRING:
lua_pushobject(L, o); lua_pushobject(L, o);
return; return;
case LUA_T_ARRAY: case TAG_ARRAY:
sprintf(buff, "table: %p", o->value.a); sprintf(buff, "table: %p", o->value.a);
break; break;
case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: case TAG_LCLOSURE: case TAG_CCLOSURE:
sprintf(buff, "function: %p", o->value.cl); sprintf(buff, "function: %p", o->value.cl);
break; break;
case LUA_T_LPROTO: case TAG_LPROTO:
sprintf(buff, "function: %p", o->value.tf); sprintf(buff, "function: %p", o->value.tf);
break; break;
case LUA_T_CPROTO: case TAG_CPROTO:
sprintf(buff, "function: %p", o->value.f); sprintf(buff, "function: %p", o->value.f);
break; break;
case LUA_T_USERDATA: case TAG_USERDATA:
sprintf(buff, "userdata: %p(%d)", o->value.ts->u.d.value, sprintf(buff, "userdata: %p(%d)", o->value.ts->u.d.value,
o->value.ts->u.d.tag); o->value.ts->u.d.tag);
break; break;
case LUA_T_NIL: case TAG_NIL:
lua_pushstring(L, "nil"); lua_pushstring(L, "nil");
return; return;
default: default:
@@ -440,10 +440,10 @@ void luaB_foreachi (lua_State *L) {
luaD_checkstack(L, 3); /* for f, key, and val */ luaD_checkstack(L, 3); /* for f, key, and val */
for (i=1; i<=n; i++) { for (i=1; i<=n; i++) {
*(L->top++) = *f; *(L->top++) = *f;
ttype(L->top) = LUA_T_NUMBER; nvalue(L->top++) = i; ttype(L->top) = TAG_NUMBER; nvalue(L->top++) = i;
*(L->top++) = *luaH_getint(L, t, i); *(L->top++) = *luaH_getint(L, t, i);
luaD_call(L, L->top-3, 1); luaD_call(L, L->top-3, 1);
if (ttype(L->top-1) != LUA_T_NIL) if (ttype(L->top-1) != TAG_NIL)
return; return;
L->top--; /* remove nil result */ L->top--; /* remove nil result */
} }
@@ -457,12 +457,12 @@ void luaB_foreach (lua_State *L) {
luaD_checkstack(L, 3); /* for f, key, and val */ luaD_checkstack(L, 3); /* for f, key, and val */
for (i=0; i<a->size; i++) { for (i=0; i<a->size; i++) {
const Node *nd = &(a->node[i]); const Node *nd = &(a->node[i]);
if (ttype(val(nd)) != LUA_T_NIL) { if (ttype(val(nd)) != TAG_NIL) {
*(L->top++) = *f; *(L->top++) = *f;
*(L->top++) = *key(nd); *(L->top++) = *key(nd);
*(L->top++) = *val(nd); *(L->top++) = *val(nd);
luaD_call(L, L->top-3, 1); luaD_call(L, L->top-3, 1);
if (ttype(L->top-1) != LUA_T_NIL) if (ttype(L->top-1) != TAG_NIL)
return; return;
L->top--; /* remove result */ L->top--; /* remove result */
} }
@@ -475,13 +475,13 @@ void luaB_foreachvar (lua_State *L) {
GlobalVar *gv; GlobalVar *gv;
luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */ luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */
for (gv = L->rootglobal; gv; gv = gv->next) { for (gv = L->rootglobal; gv; gv = gv->next) {
if (gv->value.ttype != LUA_T_NIL) { if (gv->value.ttype != TAG_NIL) {
pushtagstring(L, gv->name); /* keep (extra) name on stack to avoid GC */ pushtagstring(L, gv->name); /* keep (extra) name on stack to avoid GC */
*(L->top++) = *f; *(L->top++) = *f;
pushtagstring(L, gv->name); pushtagstring(L, gv->name);
*(L->top++) = gv->value; *(L->top++) = gv->value;
luaD_call(L, L->top-3, 1); luaD_call(L, L->top-3, 1);
if (ttype(L->top-1) != LUA_T_NIL) { if (ttype(L->top-1) != TAG_NIL) {
*(L->top-2) = *(L->top-1); /* remove extra name */ *(L->top-2) = *(L->top-1); /* remove extra name */
L->top--; L->top--;
return; return;
@@ -551,7 +551,7 @@ static int sort_comp (lua_State *L, lua_Object f, const TObject *a,
L->top += 3; L->top += 3;
luaD_call(L, L->top-3, 1); luaD_call(L, L->top-3, 1);
L->top--; L->top--;
return (ttype(L->top) != LUA_T_NIL); return (ttype(L->top) != TAG_NIL);
} }
else /* a < b? */ else /* a < b? */
return luaV_lessthan(L, a, b, L->top); return luaV_lessthan(L, a, b, L->top);
@@ -559,7 +559,7 @@ static int sort_comp (lua_State *L, lua_Object f, const TObject *a,
static void auxsort (lua_State *L, Hash *a, int l, int u, lua_Object f) { static void auxsort (lua_State *L, Hash *a, int l, int u, lua_Object f) {
StkId P = L->top++; /* temporary place for pivot */ StkId P = L->top++; /* temporary place for pivot */
ttype(P) = LUA_T_NIL; ttype(P) = TAG_NIL;
while (l < u) { /* for tail recursion */ while (l < u) { /* for tail recursion */
int i, j; int i, j;
/* sort elements a[l], a[(l+u)/2] and a[u] */ /* sort elements a[l], a[(l+u)/2] and a[u] */

172
lcode.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lcode.c,v 1.8 2000/03/09 13:57:37 roberto Exp roberto $ ** $Id: lcode.c,v 1.9 2000/03/10 14:38:10 roberto Exp roberto $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -32,8 +32,8 @@ static Instruction *previous_instruction (LexState *ls) {
if (fs->pc > fs->lasttarget) /* no jumps to current position? */ if (fs->pc > fs->lasttarget) /* no jumps to current position? */
return &fs->f->code[fs->pc-1]; /* returns previous instruction */ return &fs->f->code[fs->pc-1]; /* returns previous instruction */
else { else {
static Instruction dummy = CREATE_0(ENDCODE); static Instruction dummy = CREATE_0(OP_END);
return &dummy; /* no optimizations after an `ENDCODE' */ return &dummy; /* no optimizations after an `END' */
} }
} }
@@ -49,10 +49,10 @@ int luaK_primitivecode (LexState *ls, Instruction i) {
static void luaK_minus (LexState *ls) { static void luaK_minus (LexState *ls) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
switch(GET_OPCODE(*previous)) { switch(GET_OPCODE(*previous)) {
case PUSHINT: SETARG_S(*previous, -GETARG_S(*previous)); return; case OP_PUSHINT: SETARG_S(*previous, -GETARG_S(*previous)); return;
case PUSHNUM: SET_OPCODE(*previous, PUSHNEGNUM); return; case OP_PUSHNUM: SET_OPCODE(*previous, OP_PUSHNEGNUM); return;
case PUSHNEGNUM: SET_OPCODE(*previous, PUSHNUM); return; case OP_PUSHNEGNUM: SET_OPCODE(*previous, OP_PUSHNUM); return;
default: luaK_primitivecode(ls, CREATE_0(MINUSOP)); default: luaK_primitivecode(ls, CREATE_0(OP_MINUS));
} }
} }
@@ -61,8 +61,8 @@ static void luaK_gettable (LexState *ls) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
luaK_deltastack(ls, -1); luaK_deltastack(ls, -1);
switch(GET_OPCODE(*previous)) { switch(GET_OPCODE(*previous)) {
case PUSHSTRING: SET_OPCODE(*previous, GETDOTTED); break; case OP_PUSHSTRING: SET_OPCODE(*previous, OP_GETDOTTED); break;
default: luaK_primitivecode(ls, CREATE_0(GETTABLE)); default: luaK_primitivecode(ls, CREATE_0(OP_GETTABLE));
} }
} }
@@ -71,8 +71,8 @@ static void luaK_add (LexState *ls) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
luaK_deltastack(ls, -1); luaK_deltastack(ls, -1);
switch(GET_OPCODE(*previous)) { switch(GET_OPCODE(*previous)) {
case PUSHINT: SET_OPCODE(*previous, ADDI); break; case OP_PUSHINT: SET_OPCODE(*previous, OP_ADDI); break;
default: luaK_primitivecode(ls, CREATE_0(ADDOP)); default: luaK_primitivecode(ls, CREATE_0(OP_ADD));
} }
} }
@@ -81,11 +81,11 @@ static void luaK_sub (LexState *ls) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
luaK_deltastack(ls, -1); luaK_deltastack(ls, -1);
switch(GET_OPCODE(*previous)) { switch(GET_OPCODE(*previous)) {
case PUSHINT: case OP_PUSHINT:
SET_OPCODE(*previous, ADDI); SET_OPCODE(*previous, OP_ADDI);
SETARG_S(*previous, -GETARG_S(*previous)); SETARG_S(*previous, -GETARG_S(*previous));
break; break;
default: luaK_primitivecode(ls, CREATE_0(SUBOP)); default: luaK_primitivecode(ls, CREATE_0(OP_SUB));
} }
} }
@@ -94,43 +94,43 @@ static void luaK_conc (LexState *ls) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
luaK_deltastack(ls, -1); luaK_deltastack(ls, -1);
switch(GET_OPCODE(*previous)) { switch(GET_OPCODE(*previous)) {
case CONCOP: SETARG_U(*previous, GETARG_U(*previous)+1); break; case OP_CONC: SETARG_U(*previous, GETARG_U(*previous)+1); break;
default: luaK_primitivecode(ls, CREATE_U(CONCOP, 2)); default: luaK_primitivecode(ls, CREATE_U(OP_CONC, 2));
} }
} }
static void luaK_eq (LexState *ls) { static void luaK_eq (LexState *ls) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
if (*previous == CREATE_U(PUSHNIL, 1)) { if (*previous == CREATE_U(OP_PUSHNIL, 1)) {
*previous = CREATE_0(NOTOP); *previous = CREATE_0(OP_NOT);
luaK_deltastack(ls, -1); /* undo effect of PUSHNIL */ luaK_deltastack(ls, -1); /* undo effect of PUSHNIL */
} }
else else
luaK_S(ls, IFEQJMP, 0, -2); luaK_S(ls, OP_IFEQJMP, 0, -2);
} }
static void luaK_neq (LexState *ls) { static void luaK_neq (LexState *ls) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
if (*previous == CREATE_U(PUSHNIL, 1)) { if (*previous == CREATE_U(OP_PUSHNIL, 1)) {
ls->fs->pc--; /* remove PUSHNIL */ ls->fs->pc--; /* remove PUSHNIL */
luaK_deltastack(ls, -1); /* undo effect of PUSHNIL */ luaK_deltastack(ls, -1); /* undo effect of PUSHNIL */
} }
else else
luaK_S(ls, IFNEQJMP, 0, -2); luaK_S(ls, OP_IFNEQJMP, 0, -2);
} }
void luaK_retcode (LexState *ls, int nlocals, int nexps) { void luaK_retcode (LexState *ls, int nlocals, int nexps) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
if (nexps > 0 && GET_OPCODE(*previous) == CALL) { if (nexps > 0 && GET_OPCODE(*previous) == OP_CALL) {
LUA_ASSERT(ls->L, GETARG_B(*previous) == MULT_RET, "call should be open"); LUA_ASSERT(ls->L, GETARG_B(*previous) == MULT_RET, "call should be open");
SET_OPCODE(*previous, TAILCALL); SET_OPCODE(*previous, OP_TAILCALL);
SETARG_B(*previous, nlocals); SETARG_B(*previous, nlocals);
} }
else else
luaK_primitivecode(ls, CREATE_U(RETCODE, nlocals)); luaK_primitivecode(ls, CREATE_U(OP_RETURN, nlocals));
} }
@@ -138,8 +138,8 @@ static void luaK_pushnil (LexState *ls, int n) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
luaK_deltastack(ls, n); luaK_deltastack(ls, n);
switch(GET_OPCODE(*previous)) { switch(GET_OPCODE(*previous)) {
case PUSHNIL: SETARG_U(*previous, GETARG_U(*previous)+n); break; case OP_PUSHNIL: SETARG_U(*previous, GETARG_U(*previous)+n); break;
default: luaK_primitivecode(ls, CREATE_U(PUSHNIL, n)); default: luaK_primitivecode(ls, CREATE_U(OP_PUSHNIL, n));
} }
} }
@@ -181,7 +181,7 @@ void luaK_deltastack (LexState *ls, int delta) {
void luaK_kstr (LexState *ls, int c) { void luaK_kstr (LexState *ls, int c) {
luaK_U(ls, PUSHSTRING, c, 1); luaK_U(ls, OP_PUSHSTRING, c, 1);
} }
@@ -189,32 +189,32 @@ void luaK_kstr (LexState *ls, int c) {
#define LOOKBACKNUMS 20 /* arbitrary limit */ #define LOOKBACKNUMS 20 /* arbitrary limit */
#endif #endif
static int real_constant (LexState *ls, real r) { static int real_constant (LexState *ls, Number r) {
/* check whether `r' has appeared within the last LOOKBACKNUMS entries */ /* check whether `r' has appeared within the last LOOKBACKNUMS entries */
TProtoFunc *f = ls->fs->f; Proto *f = ls->fs->f;
int c = f->nknum; int c = f->nknum;
int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS; int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS;
while (--c >= lim) while (--c >= lim)
if (f->knum[c] == r) return c; if (f->knum[c] == r) return c;
/* not found; create a new entry */ /* not found; create a new entry */
luaM_growvector(ls->L, f->knum, f->nknum, 1, real, constantEM, MAXARG_U); luaM_growvector(ls->L, f->knum, f->nknum, 1, Number, constantEM, MAXARG_U);
c = f->nknum++; c = f->nknum++;
f->knum[c] = r; f->knum[c] = r;
return c; return c;
} }
void luaK_number (LexState *ls, real f) { void luaK_number (LexState *ls, Number f) {
if (f <= (real)MAXARG_S && (int)f == f) if (f <= (Number)MAXARG_S && (int)f == f)
luaK_S(ls, PUSHINT, (int)f, 1); /* f has a short integer value */ luaK_S(ls, OP_PUSHINT, (int)f, 1); /* f has a short integer value */
else else
luaK_U(ls, PUSHNUM, real_constant(ls, f), 1); luaK_U(ls, OP_PUSHNUM, real_constant(ls, f), 1);
} }
void luaK_adjuststack (LexState *ls, int n) { void luaK_adjuststack (LexState *ls, int n) {
if (n > 0) if (n > 0)
luaK_U(ls, POP, n, -n); luaK_U(ls, OP_POP, n, -n);
else if (n < 0) else if (n < 0)
luaK_pushnil(ls, -n); luaK_pushnil(ls, -n);
} }
@@ -223,7 +223,7 @@ void luaK_adjuststack (LexState *ls, int n) {
int luaK_lastisopen (LexState *ls) { int luaK_lastisopen (LexState *ls) {
/* check whether last instruction is an (open) function call */ /* check whether last instruction is an (open) function call */
Instruction *i = previous_instruction(ls); Instruction *i = previous_instruction(ls);
if (GET_OPCODE(*i) == CALL) { if (GET_OPCODE(*i) == OP_CALL) {
LUA_ASSERT(ls->L, GETARG_B(*i) == MULT_RET, "call should be open"); LUA_ASSERT(ls->L, GETARG_B(*i) == MULT_RET, "call should be open");
return 1; return 1;
} }
@@ -233,7 +233,7 @@ int luaK_lastisopen (LexState *ls) {
void luaK_setcallreturns (LexState *ls, int nresults) { void luaK_setcallreturns (LexState *ls, int nresults) {
Instruction *i = previous_instruction(ls); Instruction *i = previous_instruction(ls);
if (GET_OPCODE(*i) == CALL) { /* expression is a function call? */ if (GET_OPCODE(*i) == OP_CALL) { /* expression is a function call? */
LUA_ASSERT(ls->L, GETARG_B(*i) == MULT_RET, "call should be open"); LUA_ASSERT(ls->L, GETARG_B(*i) == MULT_RET, "call should be open");
SETARG_B(*i, nresults); /* set nresults */ SETARG_B(*i, nresults); /* set nresults */
luaK_deltastack(ls, nresults); /* push results */ luaK_deltastack(ls, nresults); /* push results */
@@ -249,10 +249,10 @@ static void assertglobal (LexState *ls, int index) {
static int discharge (LexState *ls, expdesc *var) { static int discharge (LexState *ls, expdesc *var) {
switch (var->k) { switch (var->k) {
case VLOCAL: case VLOCAL:
luaK_U(ls, PUSHLOCAL, var->u.index, 1); luaK_U(ls, OP_PUSHLOCAL, var->u.index, 1);
break; break;
case VGLOBAL: case VGLOBAL:
luaK_U(ls, GETGLOBAL, var->u.index, 1); luaK_U(ls, OP_GETGLOBAL, var->u.index, 1);
assertglobal(ls, var->u.index); /* make sure that there is a global */ assertglobal(ls, var->u.index); /* make sure that there is a global */
break; break;
case VINDEXED: case VINDEXED:
@@ -278,14 +278,14 @@ static void discharge1 (LexState *ls, expdesc *var) {
void luaK_storevar (LexState *ls, const expdesc *var) { void luaK_storevar (LexState *ls, const expdesc *var) {
switch (var->k) { switch (var->k) {
case VLOCAL: case VLOCAL:
luaK_U(ls, SETLOCAL, var->u.index, -1); luaK_U(ls, OP_SETLOCAL, var->u.index, -1);
break; break;
case VGLOBAL: case VGLOBAL:
luaK_U(ls, SETGLOBAL, var->u.index, -1); luaK_U(ls, OP_SETGLOBAL, var->u.index, -1);
assertglobal(ls, var->u.index); /* make sure that there is a global */ assertglobal(ls, var->u.index); /* make sure that there is a global */
break; break;
case VINDEXED: case VINDEXED:
luaK_0(ls, SETTABLEPOP, -3); luaK_0(ls, OP_SETTABLEPOP, -3);
break; break;
default: default:
LUA_INTERNALERROR(ls->L, "invalid var kind to store"); LUA_INTERNALERROR(ls->L, "invalid var kind to store");
@@ -295,17 +295,17 @@ void luaK_storevar (LexState *ls, const expdesc *var) {
static OpCode invertjump (OpCode op) { static OpCode invertjump (OpCode op) {
switch (op) { switch (op) {
case IFNEQJMP: return IFEQJMP; case OP_IFNEQJMP: return OP_IFEQJMP;
case IFEQJMP: return IFNEQJMP; case OP_IFEQJMP: return OP_IFNEQJMP;
case IFLTJMP: return IFGEJMP; case OP_IFLTJMP: return OP_IFGEJMP;
case IFLEJMP: return IFGTJMP; case OP_IFLEJMP: return OP_IFGTJMP;
case IFGTJMP: return IFLEJMP; case OP_IFGTJMP: return OP_IFLEJMP;
case IFGEJMP: return IFLTJMP; case OP_IFGEJMP: return OP_IFLTJMP;
case IFTJMP: case ONTJMP: return IFFJMP; case OP_IFTJMP: case OP_ONTJMP: return OP_IFFJMP;
case IFFJMP: case ONFJMP: return IFTJMP; case OP_IFFJMP: case OP_ONFJMP: return OP_IFTJMP;
default: default:
LUA_INTERNALERROR(NULL, "invalid jump instruction"); LUA_INTERNALERROR(NULL, "invalid jump instruction");
return ENDCODE; /* to avoid warnings */ return OP_END; /* to avoid warnings */
} }
} }
@@ -313,7 +313,7 @@ static OpCode invertjump (OpCode op) {
static void luaK_jump (LexState *ls, OpCode jump) { static void luaK_jump (LexState *ls, OpCode jump) {
Instruction *previous = previous_instruction(ls); Instruction *previous = previous_instruction(ls);
luaK_deltastack(ls, -1); luaK_deltastack(ls, -1);
if (*previous == CREATE_0(NOTOP)) if (*previous == CREATE_0(OP_NOT))
*previous = CREATE_S(invertjump(jump), 0); *previous = CREATE_S(invertjump(jump), 0);
else else
luaK_primitivecode(ls, CREATE_S(jump, 0)); luaK_primitivecode(ls, CREATE_S(jump, 0));
@@ -342,10 +342,10 @@ static void luaK_patchlistaux (LexState *ls, int list, int target,
SETARG_S(*i, special_target-(list+1)); SETARG_S(*i, special_target-(list+1));
else { else {
SETARG_S(*i, target-(list+1)); /* do the patch */ SETARG_S(*i, target-(list+1)); /* do the patch */
if (op == ONTJMP) /* remove eventual values */ if (op == OP_ONTJMP) /* remove eventual values */
SET_OPCODE(*i, IFTJMP); SET_OPCODE(*i, OP_IFTJMP);
else if (op == ONFJMP) else if (op == OP_ONFJMP)
SET_OPCODE(*i, IFFJMP); SET_OPCODE(*i, OP_IFFJMP);
} }
if (next == 0) return; if (next == 0) return;
list += next+1; list += next+1;
@@ -355,7 +355,7 @@ static void luaK_patchlistaux (LexState *ls, int list, int target,
void luaK_patchlist (LexState *ls, int list, int target) { void luaK_patchlist (LexState *ls, int list, int target) {
luaK_patchlistaux(ls, list, target, ENDCODE, 0); luaK_patchlistaux(ls, list, target, OP_END, 0);
} }
@@ -399,7 +399,7 @@ void luaK_goiftrue (LexState *ls, expdesc *v, int keepvalue) {
if (ISJUMP(GET_OPCODE(*previous))) if (ISJUMP(GET_OPCODE(*previous)))
SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous))); SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous)));
else { else {
OpCode jump = keepvalue ? ONFJMP : IFFJMP; OpCode jump = keepvalue ? OP_ONFJMP : OP_IFFJMP;
luaK_jump(ls, jump); luaK_jump(ls, jump);
} }
insert_last(fs, &v->u.l.f); insert_last(fs, &v->u.l.f);
@@ -414,7 +414,7 @@ void luaK_goiffalse (LexState *ls, expdesc *v, int keepvalue) {
discharge1(ls, v); discharge1(ls, v);
previous = fs->f->code[fs->pc-1]; previous = fs->f->code[fs->pc-1];
if (!ISJUMP(GET_OPCODE(previous))) { if (!ISJUMP(GET_OPCODE(previous))) {
OpCode jump = keepvalue ? ONTJMP : IFTJMP; OpCode jump = keepvalue ? OP_ONTJMP : OP_IFTJMP;
luaK_jump(ls, jump); luaK_jump(ls, jump);
} }
insert_last(fs, &v->u.l.t); insert_last(fs, &v->u.l.t);
@@ -440,28 +440,28 @@ void luaK_tostack (LexState *ls, expdesc *v, int onlyone) {
int final; /* position after whole expression */ int final; /* position after whole expression */
if (ISJUMP(previous)) { if (ISJUMP(previous)) {
insert_last(fs, &v->u.l.t); /* put `previous' in true list */ insert_last(fs, &v->u.l.t); /* put `previous' in true list */
p_nil = luaK_0(ls, PUSHNILJMP, 0); p_nil = luaK_0(ls, OP_PUSHNILJMP, 0);
p_1 = luaK_S(ls, PUSHINT, 1, 1); p_1 = luaK_S(ls, OP_PUSHINT, 1, 1);
} }
else { /* still may need a PUSHNIL or a PUSHINT */ else { /* still may need a PUSHNIL or a PUSHINT */
int need_nil = need_value(fs, v->u.l.f, ONFJMP); int need_nil = need_value(fs, v->u.l.f, OP_ONFJMP);
int need_1 = need_value(fs, v->u.l.t, ONTJMP); int need_1 = need_value(fs, v->u.l.t, OP_ONTJMP);
if (need_nil && need_1) { if (need_nil && need_1) {
luaK_S(ls, JMP, 2, 0); /* skip both pushes */ luaK_S(ls, OP_JMP, 2, 0); /* skip both pushes */
p_nil = luaK_0(ls, PUSHNILJMP, 0); p_nil = luaK_0(ls, OP_PUSHNILJMP, 0);
p_1 = luaK_S(ls, PUSHINT, 1, 0); p_1 = luaK_S(ls, OP_PUSHINT, 1, 0);
} }
else if (need_nil || need_1) { else if (need_nil || need_1) {
luaK_S(ls, JMP, 1, 0); /* skip one push */ luaK_S(ls, OP_JMP, 1, 0); /* skip one push */
if (need_nil) if (need_nil)
p_nil = luaK_U(ls, PUSHNIL, 1, 0); p_nil = luaK_U(ls, OP_PUSHNIL, 1, 0);
else /* need_1 */ else /* need_1 */
p_1 = luaK_S(ls, PUSHINT, 1, 0); p_1 = luaK_S(ls, OP_PUSHINT, 1, 0);
} }
} }
final = luaK_getlabel(ls); final = luaK_getlabel(ls);
luaK_patchlistaux(ls, v->u.l.f, p_nil, ONFJMP, final); luaK_patchlistaux(ls, v->u.l.f, p_nil, OP_ONFJMP, final);
luaK_patchlistaux(ls, v->u.l.t, p_1, ONTJMP, final); luaK_patchlistaux(ls, v->u.l.t, p_1, OP_ONTJMP, final);
v->u.l.f = v->u.l.t = 0; v->u.l.f = v->u.l.t = 0;
} }
} }
@@ -481,7 +481,7 @@ void luaK_prefix (LexState *ls, int op, expdesc *v) {
if (ISJUMP(GET_OPCODE(*previous))) if (ISJUMP(GET_OPCODE(*previous)))
SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous))); SET_OPCODE(*previous, invertjump(GET_OPCODE(*previous)));
else else
luaK_0(ls, NOTOP, 0); luaK_0(ls, OP_NOT, 0);
/* interchange true and false lists */ /* interchange true and false lists */
{ int temp = v->u.l.f; v->u.l.f = v->u.l.t; v->u.l.t = temp; } { int temp = v->u.l.f; v->u.l.f = v->u.l.t; v->u.l.t = temp; }
} }
@@ -489,9 +489,9 @@ void luaK_prefix (LexState *ls, int op, expdesc *v) {
void luaK_infix (LexState *ls, int op, expdesc *v) { void luaK_infix (LexState *ls, int op, expdesc *v) {
if (op == AND) if (op == TK_AND)
luaK_goiftrue(ls, v, 1); luaK_goiftrue(ls, v, 1);
else if (op == OR) else if (op == TK_OR)
luaK_goiffalse(ls, v, 1); luaK_goiffalse(ls, v, 1);
else else
luaK_tostack(ls, v, 1); /* all other binary operators need a value */ luaK_tostack(ls, v, 1); /* all other binary operators need a value */
@@ -499,13 +499,13 @@ void luaK_infix (LexState *ls, int op, expdesc *v) {
void luaK_posfix (LexState *ls, int op, expdesc *v1, expdesc *v2) { void luaK_posfix (LexState *ls, int op, expdesc *v1, expdesc *v2) {
if (op == AND) { if (op == TK_AND) {
LUA_ASSERT(ls->L, v1->u.l.t == 0, "list must be closed"); LUA_ASSERT(ls->L, v1->u.l.t == 0, "list must be closed");
discharge1(ls, v2); discharge1(ls, v2);
v1->u.l.t = v2->u.l.t; v1->u.l.t = v2->u.l.t;
concatlists(ls, &v1->u.l.f, v2->u.l.f); concatlists(ls, &v1->u.l.f, v2->u.l.f);
} }
else if (op == OR) { else if (op == TK_OR) {
LUA_ASSERT(ls->L, v1->u.l.f == 0, "list must be closed"); LUA_ASSERT(ls->L, v1->u.l.f == 0, "list must be closed");
discharge1(ls, v2); discharge1(ls, v2);
v1->u.l.f = v2->u.l.f; v1->u.l.f = v2->u.l.f;
@@ -516,16 +516,16 @@ void luaK_posfix (LexState *ls, int op, expdesc *v1, expdesc *v2) {
switch (op) { switch (op) {
case '+': luaK_add(ls); break; case '+': luaK_add(ls); break;
case '-': luaK_sub(ls); break; case '-': luaK_sub(ls); break;
case '*': luaK_0(ls, MULTOP, -1); break; case '*': luaK_0(ls, OP_MULT, -1); break;
case '/': luaK_0(ls, DIVOP, -1); break; case '/': luaK_0(ls, OP_DIV, -1); break;
case '^': luaK_0(ls, POWOP, -1); break; case '^': luaK_0(ls, OP_POW, -1); break;
case CONC: luaK_conc(ls); break; case TK_CONC: luaK_conc(ls); break;
case EQ: luaK_eq(ls); break; case TK_EQ: luaK_eq(ls); break;
case NE: luaK_neq(ls); break; case TK_NE: luaK_neq(ls); break;
case '>': luaK_S(ls, IFGTJMP, 0, -2); break; case '>': luaK_S(ls, OP_IFGTJMP, 0, -2); break;
case '<': luaK_S(ls, IFLTJMP, 0, -2); break; case '<': luaK_S(ls, OP_IFLTJMP, 0, -2); break;
case GE: luaK_S(ls, IFGEJMP, 0, -2); break; case TK_GE: luaK_S(ls, OP_IFGEJMP, 0, -2); break;
case LE: luaK_S(ls, IFLEJMP, 0, -2); break; case TK_LE: luaK_S(ls, OP_IFLEJMP, 0, -2); break;
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lcode.h,v 1.3 2000/03/03 18:53:17 roberto Exp roberto $ ** $Id: lcode.h,v 1.5 2000/03/09 13:57:37 roberto Exp roberto $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -30,7 +30,7 @@ void luaK_goiffalse (LexState *ls, expdesc *v, int keepvalue);
int luaK_getlabel (LexState *ls); int luaK_getlabel (LexState *ls);
void luaK_deltastack (LexState *ls, int delta); void luaK_deltastack (LexState *ls, int delta);
void luaK_kstr (LexState *ls, int c); void luaK_kstr (LexState *ls, int c);
void luaK_number (LexState *ls, real f); void luaK_number (LexState *ls, Number f);
void luaK_adjuststack (LexState *ls, int n); void luaK_adjuststack (LexState *ls, int n);
int luaK_lastisopen (LexState *ls); int luaK_lastisopen (LexState *ls);
void luaK_setcallreturns (LexState *ls, int nresults); void luaK_setcallreturns (LexState *ls, int nresults);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldebug.c,v 1.9 2000/02/17 18:30:36 roberto Exp roberto $ ** $Id: ldebug.c,v 1.10 2000/03/03 14:58:26 roberto Exp roberto $
** Debug Interface ** Debug Interface
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -23,11 +23,11 @@
static const lua_Type normtype[] = { /* ORDER LUA_T */ static const lua_Type normtype[] = { /* ORDER LUA_T */
LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, TAG_USERDATA, TAG_NUMBER, TAG_STRING, TAG_ARRAY,
LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, TAG_LPROTO, TAG_CPROTO, TAG_NIL,
LUA_T_LCLOSURE, LUA_T_CCLOSURE, TAG_LCLOSURE, TAG_CCLOSURE,
LUA_T_LCLOSURE, LUA_T_CCLOSURE, /* LUA_T_LCLMARK, LUA_T_CCLMARK */ TAG_LCLOSURE, TAG_CCLOSURE, /* TAG_LCLMARK, TAG_CCLMARK */
LUA_T_LPROTO, LUA_T_CPROTO /* LUA_T_LMARK, LUA_T_CMARK */ TAG_LPROTO, TAG_CPROTO /* TAG_LMARK, TAG_CMARK */
}; };
@@ -39,7 +39,7 @@ static void setnormalized (TObject *d, const TObject *s) {
static int hasdebuginfo (lua_State *L, StkId f) { static int hasdebuginfo (lua_State *L, StkId f) {
return (f+1 < L->top && (f+1)->ttype == LUA_T_LINE); return (f+1 < L->top && (f+1)->ttype == TAG_LINE);
} }
@@ -89,8 +89,8 @@ int lua_getstack (lua_State *L, int level, lua_Dbgactreg *ar) {
static int lua_nups (StkId f) { static int lua_nups (StkId f) {
switch (ttype(f)) { switch (ttype(f)) {
case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: case TAG_LCLOSURE: case TAG_CCLOSURE:
case LUA_T_LCLMARK: case LUA_T_CCLMARK: case TAG_LCLMARK: case TAG_CCLMARK:
return f->value.cl->nelems; return f->value.cl->nelems;
default: default:
return 0; return 0;
@@ -103,10 +103,10 @@ static int lua_currentline (lua_State *L, StkId f) {
} }
static TProtoFunc *getluaproto (StkId f) { static Proto *getluaproto (StkId f) {
if (ttype(f) == LUA_T_LMARK) if (ttype(f) == TAG_LMARK)
return f->value.tf; return f->value.tf;
else if (ttype(f) == LUA_T_LCLMARK) else if (ttype(f) == TAG_LCLMARK)
return protovalue(f)->value.tf; return protovalue(f)->value.tf;
else return NULL; else return NULL;
} }
@@ -114,13 +114,13 @@ static TProtoFunc *getluaproto (StkId f) {
int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) { int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
StkId f = ar->_func; StkId f = ar->_func;
TProtoFunc *fp = getluaproto(f); Proto *fp = getluaproto(f);
if (!fp) return 0; /* `f' is not a Lua function? */ if (!fp) return 0; /* `f' is not a Lua function? */
v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
if (!v->name) return 0; if (!v->name) return 0;
/* if `name', there must be a LUA_T_LINE */ /* if `name', there must be a TAG_LINE */
/* therefore, f+2 points to function base */ /* therefore, f+2 points to function base */
LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); LUA_ASSERT(L, ttype(f+1) == TAG_LINE, "");
v->value = luaA_putluaObject(L, (f+2)+(v->index-1)); v->value = luaA_putluaObject(L, (f+2)+(v->index-1));
return 1; return 1;
} }
@@ -128,11 +128,11 @@ int lua_getlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) { int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
StkId f = ar->_func; StkId f = ar->_func;
TProtoFunc *fp = getluaproto(f); Proto *fp = getluaproto(f);
if (!fp) return 0; /* `f' is not a Lua function? */ if (!fp) return 0; /* `f' is not a Lua function? */
v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f)); v->name = luaF_getlocalname(fp, v->index, lua_currentline(L, f));
if (!v->name) return 0; if (!v->name) return 0;
LUA_ASSERT(L, ttype(f+1) == LUA_T_LINE, ""); LUA_ASSERT(L, ttype(f+1) == TAG_LINE, "");
*((f+2)+(v->index-1)) = *v->value; *((f+2)+(v->index-1)) = *v->value;
return 1; return 1;
} }
@@ -141,12 +141,12 @@ int lua_setlocal (lua_State *L, const lua_Dbgactreg *ar, lua_Dbglocvar *v) {
static void lua_funcinfo (lua_Dbgactreg *ar) { static void lua_funcinfo (lua_Dbgactreg *ar) {
StkId func = ar->_func; StkId func = ar->_func;
switch (ttype(func)) { switch (ttype(func)) {
case LUA_T_LPROTO: case LUA_T_LMARK: case TAG_LPROTO: case TAG_LMARK:
ar->source = tfvalue(func)->source->str; ar->source = tfvalue(func)->source->str;
ar->linedefined = tfvalue(func)->lineDefined; ar->linedefined = tfvalue(func)->lineDefined;
ar->what = "Lua"; ar->what = "Lua";
break; break;
case LUA_T_LCLOSURE: case LUA_T_LCLMARK: case TAG_LCLOSURE: case TAG_LCLMARK:
ar->source = tfvalue(protovalue(func))->source->str; ar->source = tfvalue(protovalue(func))->source->str;
ar->linedefined = tfvalue(protovalue(func))->lineDefined; ar->linedefined = tfvalue(protovalue(func))->lineDefined;
ar->what = "Lua"; ar->what = "Lua";

28
ldo.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 1.67 2000/02/08 16:34:31 roberto Exp roberto $ ** $Id: ldo.c,v 1.68 2000/03/03 14:58:26 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -86,7 +86,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) {
else { else {
luaD_checkstack(L, diff); luaD_checkstack(L, diff);
while (diff--) while (diff--)
ttype(L->top++) = LUA_T_NIL; ttype(L->top++) = TAG_NIL;
} }
} }
@@ -191,29 +191,29 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
lua_Dbghook callhook = L->callhook; lua_Dbghook callhook = L->callhook;
retry: /* for `function' tag method */ retry: /* for `function' tag method */
switch (ttype(func)) { switch (ttype(func)) {
case LUA_T_CPROTO: case TAG_CPROTO:
ttype(func) = LUA_T_CMARK; ttype(func) = TAG_CMARK;
firstResult = callC(L, fvalue(func), func+1); firstResult = callC(L, fvalue(func), func+1);
break; break;
case LUA_T_LPROTO: case TAG_LPROTO:
ttype(func) = LUA_T_LMARK; ttype(func) = TAG_LMARK;
firstResult = luaV_execute(L, NULL, tfvalue(func), func+1); firstResult = luaV_execute(L, NULL, tfvalue(func), func+1);
break; break;
case LUA_T_LCLOSURE: { case TAG_LCLOSURE: {
Closure *c = clvalue(func); Closure *c = clvalue(func);
ttype(func) = LUA_T_LCLMARK; ttype(func) = TAG_LCLMARK;
firstResult = luaV_execute(L, c, tfvalue(c->consts), func+1); firstResult = luaV_execute(L, c, tfvalue(c->consts), func+1);
break; break;
} }
case LUA_T_CCLOSURE: { case TAG_CCLOSURE: {
Closure *c = clvalue(func); Closure *c = clvalue(func);
ttype(func) = LUA_T_CCLMARK; ttype(func) = TAG_CCLMARK;
firstResult = callCclosure(L, c, func+1); firstResult = callCclosure(L, c, func+1);
break; break;
} }
default: { /* `func' is not a function; check the `function' tag method */ default: { /* `func' is not a function; check the `function' tag method */
const TObject *im = luaT_getimbyObj(L, func, IM_FUNCTION); const TObject *im = luaT_getimbyObj(L, func, IM_FUNCTION);
if (ttype(im) == LUA_T_NIL) if (ttype(im) == TAG_NIL)
luaG_callerror(L, func); luaG_callerror(L, func);
luaD_openstack(L, func); luaD_openstack(L, func);
*func = *im; /* tag method is the new function to be called */ *func = *im; /* tag method is the new function to be called */
@@ -298,7 +298,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
StkId base = L->Cstack.base; StkId base = L->Cstack.base;
int numCblocks = L->numCblocks; int numCblocks = L->numCblocks;
int status; int status;
TProtoFunc *volatile tf; Proto *volatile tf;
struct lua_longjmp *volatile oldErr = L->errorJmp; struct lua_longjmp *volatile oldErr = L->errorJmp;
L->errorJmp = &myErrorJmp; L->errorJmp = &myErrorJmp;
L->top = base; /* clear C2Lua */ L->top = base; /* clear C2Lua */
@@ -316,7 +316,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
L->errorJmp = oldErr; L->errorJmp = oldErr;
if (status) return 1; /* error code */ if (status) return 1; /* error code */
if (tf == NULL) return 2; /* `natural' end */ if (tf == NULL) return 2; /* `natural' end */
L->top->ttype = LUA_T_LPROTO; /* push new function on the stack */ L->top->ttype = TAG_LPROTO; /* push new function on the stack */
L->top->value.tf = tf; L->top->value.tf = tf;
incr_top; incr_top;
return 0; return 0;
@@ -345,7 +345,7 @@ static int do_main (lua_State *L, ZIO *z, int bin) {
void luaD_gcIM (lua_State *L, const TObject *o) { void luaD_gcIM (lua_State *L, const TObject *o) {
const TObject *im = luaT_getimbyObj(L, o, IM_GC); const TObject *im = luaT_getimbyObj(L, o, IM_GC);
if (ttype(im) != LUA_T_NIL) { if (ttype(im) != TAG_NIL) {
luaD_checkstack(L, 2); luaD_checkstack(L, 2);
*(L->top++) = *im; *(L->top++) = *im;
*(L->top++) = *o; *(L->top++) = *o;

12
lfunc.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lfunc.c,v 1.18 2000/01/28 16:53:00 roberto Exp roberto $ ** $Id: lfunc.c,v 1.19 2000/03/03 14:58:26 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures ** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -13,7 +13,7 @@
#include "lmem.h" #include "lmem.h"
#include "lstate.h" #include "lstate.h"
#define gcsizeproto(L, p) numblocks(L, 0, sizeof(TProtoFunc)) #define gcsizeproto(L, p) numblocks(L, 0, sizeof(Proto))
#define gcsizeclosure(L, c) numblocks(L, c->nelems, sizeof(Closure)) #define gcsizeclosure(L, c) numblocks(L, c->nelems, sizeof(Closure))
@@ -29,8 +29,8 @@ Closure *luaF_newclosure (lua_State *L, int nelems) {
} }
TProtoFunc *luaF_newproto (lua_State *L) { Proto *luaF_newproto (lua_State *L) {
TProtoFunc *f = luaM_new(L, TProtoFunc); Proto *f = luaM_new(L, Proto);
f->code = NULL; f->code = NULL;
f->lineDefined = 0; f->lineDefined = 0;
f->source = NULL; f->source = NULL;
@@ -49,7 +49,7 @@ TProtoFunc *luaF_newproto (lua_State *L) {
} }
void luaF_freeproto (lua_State *L, TProtoFunc *f) { void luaF_freeproto (lua_State *L, Proto *f) {
L->nblocks -= gcsizeproto(L, f); L->nblocks -= gcsizeproto(L, f);
luaM_free(L, f->code); luaM_free(L, f->code);
luaM_free(L, f->locvars); luaM_free(L, f->locvars);
@@ -70,7 +70,7 @@ void luaF_freeclosure (lua_State *L, Closure *c) {
** Look for n-th local variable at line `line' in function `func'. ** Look for n-th local variable at line `line' in function `func'.
** Returns NULL if not found. ** Returns NULL if not found.
*/ */
const char *luaF_getlocalname (const TProtoFunc *func, const char *luaF_getlocalname (const Proto *func,
int local_number, int line) { int local_number, int line) {
int count = 0; int count = 0;
const char *varname = NULL; const char *varname = NULL;

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lfunc.h,v 1.9 1999/11/22 13:12:07 roberto Exp roberto $ ** $Id: lfunc.h,v 1.10 1999/12/27 17:33:22 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures ** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -12,12 +12,12 @@
TProtoFunc *luaF_newproto (lua_State *L); Proto *luaF_newproto (lua_State *L);
Closure *luaF_newclosure (lua_State *L, int nelems); Closure *luaF_newclosure (lua_State *L, int nelems);
void luaF_freeproto (lua_State *L, TProtoFunc *f); void luaF_freeproto (lua_State *L, Proto *f);
void luaF_freeclosure (lua_State *L, Closure *c); void luaF_freeclosure (lua_State *L, Closure *c);
const char *luaF_getlocalname (const TProtoFunc *func, const char *luaF_getlocalname (const Proto *func,
int local_number, int line); int local_number, int line);

30
lgc.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 1.40 2000/01/25 13:57:18 roberto Exp roberto $ ** $Id: lgc.c,v 1.41 2000/01/28 16:53:00 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -28,7 +28,7 @@ static int markobject (lua_State *L, TObject *o);
static void protomark (lua_State *L, TProtoFunc *f) { static void protomark (lua_State *L, Proto *f) {
if (!f->marked) { if (!f->marked) {
int i; int i;
f->marked = 1; f->marked = 1;
@@ -57,7 +57,7 @@ static void hashmark (lua_State *L, Hash *h) {
h->marked = 1; h->marked = 1;
for (i=h->size-1; i>=0; i--) { for (i=h->size-1; i>=0; i--) {
Node *n = node(h,i); Node *n = node(h,i);
if (ttype(key(n)) != LUA_T_NIL) { if (ttype(key(n)) != TAG_NIL) {
markobject(L, &n->key); markobject(L, &n->key);
markobject(L, &n->val); markobject(L, &n->val);
} }
@@ -70,7 +70,7 @@ static void travglobal (lua_State *L) {
GlobalVar *gv; GlobalVar *gv;
for (gv=L->rootglobal; gv; gv=gv->next) { for (gv=L->rootglobal; gv; gv=gv->next) {
LUA_ASSERT(L, gv->name->u.s.gv == gv, "inconsistent global name"); LUA_ASSERT(L, gv->name->u.s.gv == gv, "inconsistent global name");
if (gv->value.ttype != LUA_T_NIL) { if (gv->value.ttype != TAG_NIL) {
strmark(L, gv->name); /* cannot collect non nil global variables */ strmark(L, gv->name); /* cannot collect non nil global variables */
markobject(L, &gv->value); markobject(L, &gv->value);
} }
@@ -96,17 +96,17 @@ static void travlock (lua_State *L) {
static int markobject (lua_State *L, TObject *o) { static int markobject (lua_State *L, TObject *o) {
switch (ttype(o)) { switch (ttype(o)) {
case LUA_T_USERDATA: case LUA_T_STRING: case TAG_USERDATA: case TAG_STRING:
strmark(L, tsvalue(o)); strmark(L, tsvalue(o));
break; break;
case LUA_T_ARRAY: case TAG_ARRAY:
hashmark(L, avalue(o)); hashmark(L, avalue(o));
break; break;
case LUA_T_LCLOSURE: case LUA_T_LCLMARK: case TAG_LCLOSURE: case TAG_LCLMARK:
case LUA_T_CCLOSURE: case LUA_T_CCLMARK: case TAG_CCLOSURE: case TAG_CCLMARK:
closuremark(L, o->value.cl); closuremark(L, o->value.cl);
break; break;
case LUA_T_LPROTO: case LUA_T_LMARK: case TAG_LPROTO: case TAG_LMARK:
protomark(L, o->value.tf); protomark(L, o->value.tf);
break; break;
default: break; /* numbers, cprotos, etc */ default: break; /* numbers, cprotos, etc */
@@ -116,8 +116,8 @@ static int markobject (lua_State *L, TObject *o) {
static void collectproto (lua_State *L) { static void collectproto (lua_State *L) {
TProtoFunc **p = &L->rootproto; Proto **p = &L->rootproto;
TProtoFunc *next; Proto *next;
while ((next = *p) != NULL) { while ((next = *p) != NULL) {
if (next->marked) { if (next->marked) {
next->marked = 0; next->marked = 0;
@@ -185,14 +185,14 @@ static void clear_global_list (lua_State *L, int limit) {
static void collectstring (lua_State *L, int limit) { static void collectstring (lua_State *L, int limit) {
TObject o; /* to call userdata `gc' tag method */ TObject o; /* to call userdata `gc' tag method */
int i; int i;
ttype(&o) = LUA_T_USERDATA; ttype(&o) = TAG_USERDATA;
clear_global_list(L, limit); clear_global_list(L, limit);
for (i=0; i<NUM_HASHS; i++) { /* for each hash table */ for (i=0; i<NUM_HASHS; i++) { /* for each hash table */
stringtable *tb = &L->string_root[i]; stringtable *tb = &L->string_root[i];
int j; int j;
for (j=0; j<tb->size; j++) { /* for each list */ for (j=0; j<tb->size; j++) { /* for each list */
TaggedString **p = &tb->hash[j]; TString **p = &tb->hash[j];
TaggedString *next; TString *next;
while ((next = *p) != NULL) { while ((next = *p) != NULL) {
if (next->marked >= limit) { if (next->marked >= limit) {
if (next->marked < FIXMARK) /* does not change FIXMARKs */ if (next->marked < FIXMARK) /* does not change FIXMARKs */
@@ -220,7 +220,7 @@ static void collectstring (lua_State *L, int limit) {
static void tableTM (lua_State *L) { static void tableTM (lua_State *L) {
Hash *p; Hash *p;
TObject o; TObject o;
ttype(&o) = LUA_T_ARRAY; ttype(&o) = TAG_ARRAY;
for (p = L->roottable; p; p = p->next) { for (p = L->roottable; p; p = p->next) {
if (!p->marked) { if (!p->marked) {
avalue(&o) = p; avalue(&o) = p;

42
llex.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: llex.c,v 1.51 2000/02/08 16:34:31 roberto Exp roberto $ ** $Id: llex.c,v 1.52 2000/03/03 14:58:26 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -39,7 +39,7 @@ static const char *const token2string [] = {"and", "do", "else", "elseif", "end"
void luaX_init (lua_State *L) { void luaX_init (lua_State *L) {
int i; int i;
for (i=0; i<NUM_RESERVED; i++) { for (i=0; i<NUM_RESERVED; i++) {
TaggedString *ts = luaS_new(L, token2string[i]); TString *ts = luaS_new(L, token2string[i]);
ts->marked = (unsigned char)(RESERVEDMARK+i); /* reserved word */ ts->marked = (unsigned char)(RESERVEDMARK+i); /* reserved word */
} }
} }
@@ -160,7 +160,7 @@ static void ifskip (lua_State *L, LexState *LS) {
if (LS->current == '\n') if (LS->current == '\n')
inclinenumber(L, LS); inclinenumber(L, LS);
else if (LS->current == EOZ) else if (LS->current == EOZ)
luaX_error(LS, "input ends inside a $if", EOS); luaX_error(LS, "input ends inside a $if", TK_EOS);
else next(LS); else next(LS);
} }
} }
@@ -240,7 +240,7 @@ static void read_long_string (lua_State *L, LexState *LS) {
for (;;) { for (;;) {
switch (LS->current) { switch (LS->current) {
case EOZ: case EOZ:
luaX_error(LS, "unfinished long string", STRING); luaX_error(LS, "unfinished long string", TK_STRING);
break; /* to avoid warnings */ break; /* to avoid warnings */
case '[': case '[':
save_and_next(L, LS); save_and_next(L, LS);
@@ -276,7 +276,7 @@ static void read_string (lua_State *L, LexState *LS, int del) {
while (LS->current != del) { while (LS->current != del) {
switch (LS->current) { switch (LS->current) {
case EOZ: case '\n': case EOZ: case '\n':
luaX_error(LS, "unfinished string", STRING); luaX_error(LS, "unfinished string", TK_STRING);
break; /* to avoid warnings */ break; /* to avoid warnings */
case '\\': case '\\':
next(LS); /* do not save the '\' */ next(LS); /* do not save the '\' */
@@ -298,7 +298,7 @@ static void read_string (lua_State *L, LexState *LS, int del) {
next(LS); next(LS);
} while (++i<3 && isdigit(LS->current)); } while (++i<3 && isdigit(LS->current));
if (c != (unsigned char)c) if (c != (unsigned char)c)
luaX_error(LS, "escape sequence too large", STRING); luaX_error(LS, "escape sequence too large", TK_STRING);
save(L, c); save(L, c);
break; break;
} }
@@ -343,34 +343,34 @@ int luaX_lex (LexState *LS) {
else { else {
save_and_next(L, LS); /* pass the second '[' */ save_and_next(L, LS); /* pass the second '[' */
read_long_string(L, LS); read_long_string(L, LS);
return STRING; return TK_STRING;
} }
case '=': case '=':
next(LS); next(LS);
if (LS->current != '=') return '='; if (LS->current != '=') return '=';
else { next(LS); return EQ; } else { next(LS); return TK_EQ; }
case '<': case '<':
next(LS); next(LS);
if (LS->current != '=') return '<'; if (LS->current != '=') return '<';
else { next(LS); return LE; } else { next(LS); return TK_LE; }
case '>': case '>':
next(LS); next(LS);
if (LS->current != '=') return '>'; if (LS->current != '=') return '>';
else { next(LS); return GE; } else { next(LS); return TK_GE; }
case '~': case '~':
next(LS); next(LS);
if (LS->current != '=') return '~'; if (LS->current != '=') return '~';
else { next(LS); return NE; } else { next(LS); return TK_NE; }
case '"': case '"':
case '\'': case '\'':
luaL_resetbuffer(L); luaL_resetbuffer(L);
read_string(L, LS, LS->current); read_string(L, LS, LS->current);
return STRING; return TK_STRING;
case '.': case '.':
luaL_resetbuffer(L); luaL_resetbuffer(L);
@@ -379,9 +379,9 @@ int luaX_lex (LexState *LS) {
next(LS); next(LS);
if (LS->current == '.') { if (LS->current == '.') {
next(LS); next(LS);
return DOTS; /* ... */ return TK_DOTS; /* ... */
} }
else return CONC; /* .. */ else return TK_CONC; /* .. */
} }
else if (!isdigit(LS->current)) return '.'; else if (!isdigit(LS->current)) return '.';
else goto fraction; /* LS->current is a digit */ else goto fraction; /* LS->current is a digit */
@@ -397,7 +397,7 @@ int luaX_lex (LexState *LS) {
if (LS->current == '.') { if (LS->current == '.') {
save(L, '.'); save(L, '.');
luaX_error(LS, "ambiguous syntax" luaX_error(LS, "ambiguous syntax"
" (decimal point x string concatenation)", NUMBER); " (decimal point x string concatenation)", TK_NUMBER);
} }
} }
fraction: /* LUA_NUMBER */ fraction: /* LUA_NUMBER */
@@ -412,13 +412,13 @@ int luaX_lex (LexState *LS) {
} }
save(L, '\0'); save(L, '\0');
if (!luaO_str2d(L->Mbuffer+L->Mbuffbase, &LS->seminfo.r)) if (!luaO_str2d(L->Mbuffer+L->Mbuffbase, &LS->seminfo.r))
luaX_error(LS, "malformed number", NUMBER); luaX_error(LS, "malformed number", TK_NUMBER);
return NUMBER; return TK_NUMBER;
case EOZ: case EOZ:
if (LS->iflevel > 0) if (LS->iflevel > 0)
luaX_error(LS, "input ends inside a $if", EOS); luaX_error(LS, "input ends inside a $if", TK_EOS);
return EOS; return TK_EOS;
case '_': goto tname; case '_': goto tname;
@@ -431,7 +431,7 @@ int luaX_lex (LexState *LS) {
return c; return c;
} }
tname: { /* identifier or reserved word */ tname: { /* identifier or reserved word */
TaggedString *ts; TString *ts;
luaL_resetbuffer(L); luaL_resetbuffer(L);
do { do {
save_and_next(L, LS); save_and_next(L, LS);
@@ -441,7 +441,7 @@ int luaX_lex (LexState *LS) {
if (ts->marked >= RESERVEDMARK) /* reserved word? */ if (ts->marked >= RESERVEDMARK) /* reserved word? */
return ts->marked-RESERVEDMARK+FIRST_RESERVED; return ts->marked-RESERVEDMARK+FIRST_RESERVED;
LS->seminfo.ts = ts; LS->seminfo.ts = ts;
return NAME; return TK_NAME;
} }
} }
} }

17
llex.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: llex.h,v 1.18 2000/02/08 16:34:31 roberto Exp roberto $ ** $Id: llex.h,v 1.19 2000/03/03 14:58:26 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -23,15 +23,16 @@
*/ */
enum RESERVED { enum RESERVED {
/* terminal symbols denoted by reserved words */ /* terminal symbols denoted by reserved words */
AND = FIRST_RESERVED, TK_AND = FIRST_RESERVED,
DO, ELSE, ELSEIF, END, FUNCTION, IF, LOCAL, NIL, NOT, OR, TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FUNCTION, TK_IF, TK_LOCAL,
REPEAT, RETURN, THEN, UNTIL, WHILE, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, TK_RETURN, TK_THEN, TK_UNTIL, TK_WHILE,
/* other terminal symbols */ /* other terminal symbols */
NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS TK_NAME, TK_CONC, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
TK_STRING, TK_EOS
}; };
/* number of reserved words */ /* number of reserved words */
#define NUM_RESERVED ((int)(WHILE-FIRST_RESERVED+1)) #define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1))
#ifndef MAX_IFS #ifndef MAX_IFS
@@ -53,8 +54,8 @@ typedef struct LexState {
struct FuncState *fs; /* `FuncState' is private to the parser */ struct FuncState *fs; /* `FuncState' is private to the parser */
struct lua_State *L; struct lua_State *L;
union { union {
real r; Number r;
TaggedString *ts; TString *ts;
} seminfo; /* semantics information */ } seminfo; /* semantics information */
struct zio *z; /* input stream */ struct zio *z; /* input stream */
int linenumber; /* input line counter */ int linenumber; /* input line counter */

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lmathlib.c,v 1.22 1999/12/14 18:31:20 roberto Exp roberto $ ** $Id: lmathlib.c,v 1.23 1999/12/27 17:33:22 roberto Exp roberto $
** Standard mathematical library ** Standard mathematical library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -147,7 +147,7 @@ static void math_random (lua_State *L) {
some systems (SunOS!) "rand()" may return a value larger than RAND_MAX */ some systems (SunOS!) "rand()" may return a value larger than RAND_MAX */
double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX; double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX;
if (lua_getparam(L, 1) == LUA_NOOBJECT) /* no arguments? */ if (lua_getparam(L, 1) == LUA_NOOBJECT) /* no arguments? */
lua_pushnumber(L, r); /* real between 0 and 1 */ lua_pushnumber(L, r); /* Number between 0 and 1 */
else { else {
int l, u; /* lower & upper limits */ int l, u; /* lower & upper limits */
if (lua_getparam(L, 2) == LUA_NOOBJECT) { /* only one argument? */ if (lua_getparam(L, 2) == LUA_NOOBJECT) { /* only one argument? */

4
lmem.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lmem.c,v 1.26 2000/03/03 14:58:26 roberto Exp roberto $ ** $Id: lmem.c,v 1.27 2000/03/10 14:01:05 roberto Exp roberto $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -16,7 +16,7 @@
/* /*
** real ANSI systems do not need these tests; ** Number ANSI systems do not need these tests;
** but some systems (Sun OS) are not that ANSI... ** but some systems (Sun OS) are not that ANSI...
*/ */
#ifdef OLD_ANSI #ifdef OLD_ANSI

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lobject.c,v 1.31 2000/02/17 18:30:36 roberto Exp roberto $ ** $Id: lobject.c,v 1.32 2000/03/03 14:58:26 roberto Exp roberto $
** Some generic functions over Lua objects ** Some generic functions over Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -20,7 +20,7 @@ const char *const luaO_typenames[] = { /* ORDER LUA_T */
}; };
const TObject luaO_nilobject = {LUA_T_NIL, {NULL}}; const TObject luaO_nilobject = {TAG_NIL, {NULL}};
/* /*
@@ -35,19 +35,19 @@ unsigned long luaO_power2 (unsigned long n) {
int luaO_equalval (const TObject *t1, const TObject *t2) { int luaO_equalval (const TObject *t1, const TObject *t2) {
switch (ttype(t1)) { switch (ttype(t1)) {
case LUA_T_NIL: case TAG_NIL:
return 1; return 1;
case LUA_T_NUMBER: case TAG_NUMBER:
return nvalue(t1) == nvalue(t2); return nvalue(t1) == nvalue(t2);
case LUA_T_STRING: case LUA_T_USERDATA: case TAG_STRING: case TAG_USERDATA:
return svalue(t1) == svalue(t2); return svalue(t1) == svalue(t2);
case LUA_T_ARRAY: case TAG_ARRAY:
return avalue(t1) == avalue(t2); return avalue(t1) == avalue(t2);
case LUA_T_LPROTO: case TAG_LPROTO:
return tfvalue(t1) == tfvalue(t2); return tfvalue(t1) == tfvalue(t2);
case LUA_T_CPROTO: case TAG_CPROTO:
return fvalue(t1) == fvalue(t2); return fvalue(t1) == fvalue(t2);
case LUA_T_CCLOSURE: case LUA_T_LCLOSURE: case TAG_CCLOSURE: case TAG_LCLOSURE:
return t1->value.cl == t2->value.cl; return t1->value.cl == t2->value.cl;
default: default:
LUA_INTERNALERROR(L, "invalid type"); LUA_INTERNALERROR(L, "invalid type");
@@ -67,7 +67,7 @@ static double expten (unsigned int e) {
} }
int luaO_str2d (const char *s, real *result) { /* LUA_NUMBER */ int luaO_str2d (const char *s, Number *result) { /* LUA_NUMBER */
double a = 0.0; double a = 0.0;
int point = 0; /* number of decimal digits */ int point = 0; /* number of decimal digits */
int sig; int sig;

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lobject.h,v 1.49 2000/02/21 18:33:26 roberto Exp roberto $ ** $Id: lobject.h,v 1.50 2000/03/03 14:58:26 roberto Exp roberto $
** Type definitions for Lua objects ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -27,14 +27,14 @@
#define UNUSED(x) (void)x /* to avoid warnings */ #define UNUSED(x) (void)x /* to avoid warnings */
/* /*
** "real" is the type "number" of Lua ** Define the type `number' of Lua
** GREP LUA_NUMBER to change that ** GREP LUA_NUMBER to change that
*/ */
#ifndef LUA_NUM_TYPE #ifndef LUA_NUM_TYPE
#define LUA_NUM_TYPE double #define LUA_NUM_TYPE double
#endif #endif
typedef LUA_NUM_TYPE real; typedef LUA_NUM_TYPE Number;
/* /*
@@ -66,45 +66,45 @@ typedef unsigned long Instruction;
** grep "ORDER LUA_T" ** grep "ORDER LUA_T"
*/ */
typedef enum { typedef enum {
LUA_T_USERDATA = 0, /* default tag for userdata */ TAG_USERDATA = 0, /* default tag for userdata */
LUA_T_NUMBER = -1, /* fixed tag for numbers */ TAG_NUMBER = -1, /* fixed tag for numbers */
LUA_T_STRING = -2, /* fixed tag for strings */ TAG_STRING = -2, /* fixed tag for strings */
LUA_T_ARRAY = -3, /* default tag for tables (or arrays) */ TAG_ARRAY = -3, /* default tag for tables (or arrays) */
LUA_T_LPROTO = -4, /* fixed tag for Lua functions */ TAG_LPROTO = -4, /* fixed tag for Lua functions */
LUA_T_CPROTO = -5, /* fixed tag for C functions */ TAG_CPROTO = -5, /* fixed tag for C functions */
LUA_T_NIL = -6, /* last "pre-defined" tag */ TAG_NIL = -6, /* last "pre-defined" tag */
LUA_T_LCLOSURE = -7, /* Lua closure */ TAG_LCLOSURE = -7, /* Lua closure */
LUA_T_CCLOSURE = -8, /* C closure */ TAG_CCLOSURE = -8, /* C closure */
LUA_T_LCLMARK = -9 ,/* mark for Lua closures */ TAG_LCLMARK = -9 ,/* mark for Lua closures */
LUA_T_CCLMARK = -10,/* mark for C closures */ TAG_CCLMARK = -10,/* mark for C closures */
LUA_T_LMARK = -11,/* mark for Lua prototypes */ TAG_LMARK = -11,/* mark for Lua prototypes */
LUA_T_CMARK = -12,/* mark for C prototypes */ TAG_CMARK = -12,/* mark for C prototypes */
LUA_T_LINE = -13 TAG_LINE = -13
} lua_Type; } lua_Type;
#define NUM_TAGS 7 /* tags for values visible from Lua */ #define NUM_TAGS 7 /* tags for values visible from Lua */
#define LAST_REGULAR_TAG LUA_T_CCLOSURE /* after that, are all marks */ #define LAST_REGULAR_TAG TAG_CCLOSURE /* after that, are all marks */
/* /*
** check whether `t' is a mark; ttypes are negative numbers, so the ** check whether `t' is a mark; ttypes are negative numbers, so the
** comparisons look reversed. (ORDER LUA_T) ** comparisons look reversed. (ORDER LUA_T)
*/ */
#define is_T_MARK(t) (LUA_T_CMARK <= (t) && (t) <= LUA_T_LCLMARK) #define is_T_MARK(t) (TAG_CMARK <= (t) && (t) <= TAG_LCLMARK)
typedef union { typedef union {
lua_CFunction f; /* LUA_T_CPROTO, LUA_T_CMARK */ lua_CFunction f; /* TAG_CPROTO, TAG_CMARK */
real n; /* LUA_T_NUMBER */ Number n; /* TAG_NUMBER */
struct TaggedString *ts; /* LUA_T_STRING, LUA_T_USERDATA */ struct TString *ts; /* TAG_STRING, TAG_USERDATA */
struct TProtoFunc *tf; /* LUA_T_LPROTO, LUA_T_LMARK */ struct Proto *tf; /* TAG_LPROTO, TAG_LMARK */
struct Closure *cl; /* LUA_T_[CL]CLOSURE, LUA_T_[CL]CLMARK */ struct Closure *cl; /* TAG_[CL]CLOSURE, TAG_[CL]CLMARK */
struct Hash *a; /* LUA_T_ARRAY */ struct Hash *a; /* TAG_ARRAY */
int i; /* LUA_T_LINE */ int i; /* TAG_LINE */
} Value; } Value;
@@ -118,14 +118,14 @@ typedef struct TObject {
typedef struct GlobalVar { typedef struct GlobalVar {
TObject value; TObject value;
struct GlobalVar *next; struct GlobalVar *next;
struct TaggedString *name; struct TString *name;
} GlobalVar; } GlobalVar;
/* /*
** String headers for string table ** String headers for string table
*/ */
typedef struct TaggedString { typedef struct TString {
union { union {
struct { /* for strings */ struct { /* for strings */
GlobalVar *gv; /* eventual global value with this name */ GlobalVar *gv; /* eventual global value with this name */
@@ -136,12 +136,12 @@ typedef struct TaggedString {
void *value; void *value;
} d; } d;
} u; } u;
struct TaggedString *nexthash; /* chain for hash table */ struct TString *nexthash; /* chain for hash table */
unsigned long hash; unsigned long hash;
int constindex; /* hint to reuse constants (= -1 if this is a userdata) */ int constindex; /* hint to reuse constants (= -1 if this is a userdata) */
unsigned char marked; unsigned char marked;
char str[1]; /* \0 byte already reserved */ char str[1]; /* \0 byte already reserved */
} TaggedString; } TString;
@@ -149,27 +149,27 @@ typedef struct TaggedString {
/* /*
** Function Prototypes ** Function Prototypes
*/ */
typedef struct TProtoFunc { typedef struct Proto {
struct TProtoFunc *next; struct Proto *next;
int marked; int marked;
struct TaggedString **kstr; /* strings used by the function */ struct TString **kstr; /* strings used by the function */
int nkstr; /* size of `kstr' */ int nkstr; /* size of `kstr' */
real *knum; /* real numbers used by the function */ Number *knum; /* Number numbers used by the function */
int nknum; /* size of `knum' */ int nknum; /* size of `knum' */
struct TProtoFunc **kproto; /* functions defined inside the function */ struct Proto **kproto; /* functions defined inside the function */
int nkproto; /* size of `kproto' */ int nkproto; /* size of `kproto' */
Instruction *code; /* ends with opcode ENDCODE */ Instruction *code; /* ends with opcode ENDCODE */
int lineDefined; int lineDefined;
TaggedString *source; TString *source;
int numparams; int numparams;
int is_vararg; int is_vararg;
int maxstacksize; int maxstacksize;
struct LocVar *locvars; /* ends with line = -1 */ struct LocVar *locvars; /* ends with line = -1 */
} TProtoFunc; } Proto;
typedef struct LocVar { typedef struct LocVar {
TaggedString *varname; /* NULL signals end of scope */ TString *varname; /* NULL signals end of scope */
int line; int line;
} LocVar; } LocVar;
@@ -202,10 +202,10 @@ typedef struct Closure {
typedef struct node { typedef struct Node {
TObject key; TObject key;
TObject val; TObject val;
struct node *next; /* for chaining */ struct Node *next; /* for chaining */
} Node; } Node;
typedef struct Hash { typedef struct Hash {
@@ -230,7 +230,7 @@ unsigned long luaO_power2 (unsigned long n);
#define luaO_equalObj(t1,t2) (ttype(t1) == ttype(t2) && luaO_equalval(t1,t2)) #define luaO_equalObj(t1,t2) (ttype(t1) == ttype(t2) && luaO_equalval(t1,t2))
int luaO_equalval (const TObject *t1, const TObject *t2); int luaO_equalval (const TObject *t1, const TObject *t2);
int luaO_redimension (lua_State *L, int oldsize); int luaO_redimension (lua_State *L, int oldsize);
int luaO_str2d (const char *s, real *result); int luaO_str2d (const char *s, Number *result);
#endif #endif

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.h,v 1.44 2000/03/03 18:53:17 roberto Exp roberto $ ** $Id: lopcodes.h,v 1.47 2000/03/09 13:57:37 roberto Exp roberto $
** Opcodes for Lua virtual machine ** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -20,7 +20,7 @@
type 3: 1st unsigned argument in the higher 16 bits (`A') type 3: 1st unsigned argument in the higher 16 bits (`A')
2nd unsigned argument in the middle 8 bits (`B') 2nd unsigned argument in the middle 8 bits (`B')
The signed argument is represented in excess 2^23; that is, the real value The signed argument is represented in excess 2^23; that is, the Number value
is the usigned value minus 2^23. is the usigned value minus 2^23.
===========================================================================*/ ===========================================================================*/
@@ -88,73 +88,73 @@ typedef enum {
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
name args stack before stack after side effects name args stack before stack after side effects
------------------------------------------------------------------------*/ ------------------------------------------------------------------------*/
ENDCODE,/* - - (return) */ OP_END,/* - - (return) */
RETCODE,/* U - (return) */ OP_RETURN,/* U - (return) */
CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */ OP_CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */
TAILCALL,/* A B v_a-v_1 f (return) f(v1,...,v_a) */ OP_TAILCALL,/* A B v_a-v_1 f (return) f(v1,...,v_a) */
PUSHNIL,/* U - nil_1-nil_u */ OP_PUSHNIL,/* U - nil_1-nil_u */
POP,/* U a_u-a_1 - */ OP_POP,/* U a_u-a_1 - */
PUSHINT,/* S - (real)s */ OP_PUSHINT,/* S - (Number)s */
PUSHSTRING,/* K - KSTR[k] */ OP_PUSHSTRING,/* K - KSTR[k] */
PUSHNUM,/* N - KNUM[u] */ OP_PUSHNUM,/* N - KNUM[u] */
PUSHNEGNUM,/* N - -KNUM[u] */ OP_PUSHNEGNUM,/* N - -KNUM[u] */
PUSHUPVALUE,/* U - Closure[u] */ OP_PUSHUPVALUE,/* U - Closure[u] */
PUSHLOCAL,/* L - LOC[u] */ OP_PUSHLOCAL,/* L - LOC[u] */
GETGLOBAL,/* K - VAR[KSTR[k]] */ OP_GETGLOBAL,/* K - VAR[KSTR[k]] */
GETTABLE,/* - i t t[i] */ OP_GETTABLE,/* - i t t[i] */
GETDOTTED,/* K t t[KSTR[k]] */ OP_GETDOTTED,/* K t t[KSTR[k]] */
PUSHSELF,/* K t t t[KSTR[k]] */ OP_PUSHSELF,/* K t t t[KSTR[k]] */
CREATETABLE,/* U - newarray(size = u) */ OP_CREATETABLE,/* U - newarray(size = u) */
SETLOCAL,/* L x - LOC[u]=x */ OP_SETLOCAL,/* L x - LOC[u]=x */
SETGLOBAL,/* K x - VAR[KSTR[k]]=x */ OP_SETGLOBAL,/* K x - VAR[KSTR[k]]=x */
SETTABLEPOP,/* - v i t - t[i]=v */ OP_SETTABLEPOP,/* - v i t - t[i]=v */
SETTABLE,/* U v a_u-a_1 i t a_u-a_1 i t t[i]=v */ OP_SETTABLE,/* U v a_u-a_1 i t a_u-a_1 i t t[i]=v */
SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */ OP_SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */
SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */ OP_SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */
ADDOP,/* - y x x+y */ OP_ADD,/* - y x x+y */
ADDI,/* S x x+s */ OP_ADDI,/* S x x+s */
SUBOP,/* - y x x-y */ OP_SUB,/* - y x x-y */
MULTOP,/* - y x x*y */ OP_MULT,/* - y x x*y */
DIVOP,/* - y x x/y */ OP_DIV,/* - y x x/y */
POWOP,/* - y x x^y */ OP_POW,/* - y x x^y */
CONCOP,/* U v_u-v_1 v1..-..v_u */ OP_CONC,/* U v_u-v_1 v1..-..v_u */
MINUSOP,/* - x -x */ OP_MINUS,/* - x -x */
NOTOP,/* - x (x==nil)? 1 : nil */ OP_NOT,/* - x (x==nil)? 1 : nil */
IFNEQJMP,/* J y x - (x~=y)? PC+=s */ OP_IFNEQJMP,/* J y x - (x~=y)? PC+=s */
IFEQJMP,/* J y x - (x==y)? PC+=s */ OP_IFEQJMP,/* J y x - (x==y)? PC+=s */
IFLTJMP,/* J y x - (x<y)? PC+=s */ OP_IFLTJMP,/* J y x - (x<y)? PC+=s */
IFLEJMP,/* J y x - (x<y)? PC+=s */ OP_IFLEJMP,/* J y x - (x<y)? PC+=s */
IFGTJMP,/* J y x - (x>y)? PC+=s */ OP_IFGTJMP,/* J y x - (x>y)? PC+=s */
IFGEJMP,/* J y x - (x>=y)? PC+=s */ OP_IFGEJMP,/* J y x - (x>=y)? PC+=s */
IFTJMP,/* J x - (x!=nil)? PC+=s */ OP_IFTJMP,/* J x - (x!=nil)? PC+=s */
IFFJMP,/* J x - (x==nil)? PC+=s */ OP_IFFJMP,/* J x - (x==nil)? PC+=s */
ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ OP_ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */
ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */ OP_ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */
JMP,/* J - - PC+=s */ OP_JMP,/* J - - PC+=s */
PUSHNILJMP,/* - - nil PC++; */ OP_PUSHNILJMP,/* - - nil PC++; */
CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_1-v_b) */ OP_CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_1-v_b) */
SETLINE/* U - - LINE=u */ OP_SETLINE/* U - - LINE=u */
} OpCode; } OpCode;
#define ISJUMP(o) (IFNEQJMP <= (o) && (o) <= JMP) #define ISJUMP(o) (OP_IFNEQJMP <= (o) && (o) <= OP_JMP)
#define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */

158
lparser.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 1.64 2000/03/03 20:29:25 roberto Exp roberto $ ** $Id: lparser.c,v 1.67 2000/03/09 13:57:37 roberto Exp roberto $
** LL(1) Parser and code generator for Lua ** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -116,7 +116,7 @@ static void checklimit (LexState *ls, int val, int limit, const char *msg) {
static void check_debugline (LexState *ls) { static void check_debugline (LexState *ls) {
if (ls->L->debug && ls->linenumber != ls->fs->lastsetline) { if (ls->L->debug && ls->linenumber != ls->fs->lastsetline) {
luaK_U(ls, SETLINE, ls->linenumber, 0); luaK_U(ls, OP_SETLINE, ls->linenumber, 0);
ls->fs->lastsetline = ls->linenumber; ls->fs->lastsetline = ls->linenumber;
} }
} }
@@ -130,11 +130,11 @@ static void check_match (LexState *ls, int what, int who, int where) {
} }
static int string_constant (LexState *ls, FuncState *fs, TaggedString *s) { static int string_constant (LexState *ls, FuncState *fs, TString *s) {
TProtoFunc *f = fs->f; Proto *f = fs->f;
int c = s->constindex; int c = s->constindex;
if (c >= f->nkstr || f->kstr[c] != s) { if (c >= f->nkstr || f->kstr[c] != s) {
luaM_growvector(ls->L, f->kstr, f->nkstr, 1, TaggedString *, luaM_growvector(ls->L, f->kstr, f->nkstr, 1, TString *,
constantEM, MAXARG_U); constantEM, MAXARG_U);
c = f->nkstr++; c = f->nkstr++;
f->kstr[c] = s; f->kstr[c] = s;
@@ -144,14 +144,14 @@ static int string_constant (LexState *ls, FuncState *fs, TaggedString *s) {
} }
static void code_string (LexState *ls, TaggedString *s) { static void code_string (LexState *ls, TString *s) {
luaK_kstr(ls, string_constant(ls, ls->fs, s)); luaK_kstr(ls, string_constant(ls, ls->fs, s));
} }
static int checkname (LexState *ls) { static int checkname (LexState *ls) {
int sc; int sc;
if (ls->token != NAME) if (ls->token != TK_NAME)
luaK_error(ls, "<name> expected"); luaK_error(ls, "<name> expected");
sc = string_constant(ls, ls->fs, ls->seminfo.ts); sc = string_constant(ls, ls->fs, ls->seminfo.ts);
next(ls); next(ls);
@@ -159,17 +159,17 @@ static int checkname (LexState *ls) {
} }
static TaggedString *str_checkname (LexState *ls) { static TString *str_checkname (LexState *ls) {
int i = checkname(ls); /* this call may realloc `f->consts' */ int i = checkname(ls); /* this call may realloc `f->consts' */
return ls->fs->f->kstr[i]; return ls->fs->f->kstr[i];
} }
static void luaI_registerlocalvar (LexState *ls, TaggedString *varname, static void luaI_registerlocalvar (LexState *ls, TString *varname,
int line) { int line) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
if (fs->nvars != -1) { /* debug information? */ if (fs->nvars != -1) { /* debug information? */
TProtoFunc *f = fs->f; Proto *f = fs->f;
luaM_growvector(ls->L, f->locvars, fs->nvars, 1, LocVar, "", MAX_INT); luaM_growvector(ls->L, f->locvars, fs->nvars, 1, LocVar, "", MAX_INT);
f->locvars[fs->nvars].varname = varname; f->locvars[fs->nvars].varname = varname;
f->locvars[fs->nvars].line = line; f->locvars[fs->nvars].line = line;
@@ -183,7 +183,7 @@ static void luaI_unregisterlocalvar (LexState *ls, int line) {
} }
static void store_localvar (LexState *ls, TaggedString *name, int n) { static void store_localvar (LexState *ls, TString *name, int n) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables"); checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables");
fs->localvar[fs->nlocalvar+n] = name; fs->localvar[fs->nlocalvar+n] = name;
@@ -199,13 +199,13 @@ static void adjustlocalvars (LexState *ls, int nvars, int line) {
} }
static void add_localvar (LexState *ls, TaggedString *name) { static void add_localvar (LexState *ls, TString *name) {
store_localvar(ls, name, 0); store_localvar(ls, name, 0);
adjustlocalvars(ls, 1, 0); adjustlocalvars(ls, 1, 0);
} }
static int aux_localname (FuncState *fs, TaggedString *n) { static int aux_localname (FuncState *fs, TString *n) {
int i; int i;
for (i=fs->nlocalvar-1; i >= 0; i--) for (i=fs->nlocalvar-1; i >= 0; i--)
if (n == fs->localvar[i]) return i; /* local var index */ if (n == fs->localvar[i]) return i; /* local var index */
@@ -213,7 +213,7 @@ static int aux_localname (FuncState *fs, TaggedString *n) {
} }
static void singlevar (LexState *ls, TaggedString *n, expdesc *var, int prev) { static void singlevar (LexState *ls, TString *n, expdesc *var, int prev) {
FuncState *fs = prev ? ls->fs->prev : ls->fs; FuncState *fs = prev ? ls->fs->prev : ls->fs;
int i = aux_localname(fs, n); int i = aux_localname(fs, n);
if (i >= 0) { /* local value? */ if (i >= 0) { /* local value? */
@@ -231,7 +231,7 @@ static void singlevar (LexState *ls, TaggedString *n, expdesc *var, int prev) {
} }
static int indexupvalue (LexState *ls, TaggedString *n) { static int indexupvalue (LexState *ls, TString *n) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
expdesc v; expdesc v;
int i; int i;
@@ -248,12 +248,12 @@ static int indexupvalue (LexState *ls, TaggedString *n) {
} }
static void pushupvalue (LexState *ls, TaggedString *n) { static void pushupvalue (LexState *ls, TString *n) {
if (ls->fs->prev == NULL) if (ls->fs->prev == NULL)
luaX_syntaxerror(ls, "cannot access upvalue in main", n->str); luaX_syntaxerror(ls, "cannot access upvalue in main", n->str);
if (aux_localname(ls->fs, n) >= 0) if (aux_localname(ls->fs, n) >= 0)
luaX_syntaxerror(ls, "cannot access an upvalue in current scope", n->str); luaX_syntaxerror(ls, "cannot access an upvalue in current scope", n->str);
luaK_U(ls, PUSHUPVALUE, indexupvalue(ls, n), 1); luaK_U(ls, OP_PUSHUPVALUE, indexupvalue(ls, n), 1);
} }
@@ -308,21 +308,21 @@ static int getvarname (LexState *ls, expdesc *var) {
static void func_onstack (LexState *ls, FuncState *func) { static void func_onstack (LexState *ls, FuncState *func) {
TProtoFunc *f = ls->fs->f; Proto *f = ls->fs->f;
int i; int i;
for (i=0; i<func->nupvalues; i++) for (i=0; i<func->nupvalues; i++)
luaK_tostack(ls, &func->upvalues[i], 1); luaK_tostack(ls, &func->upvalues[i], 1);
luaM_growvector(ls->L, f->kproto, f->nkproto, 1, TProtoFunc *, luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *,
constantEM, MAXARG_A); constantEM, MAXARG_A);
f->kproto[f->nkproto++] = func->f; f->kproto[f->nkproto++] = func->f;
luaK_deltastack(ls, 1); /* CLOSURE puts one extra element before popping */ luaK_deltastack(ls, 1); /* CLOSURE puts one extra element before popping */
luaK_AB(ls, CLOSURE, f->nkproto-1, func->nupvalues, -func->nupvalues); luaK_AB(ls, OP_CLOSURE, f->nkproto-1, func->nupvalues, -func->nupvalues);
} }
static void init_state (LexState *ls, FuncState *fs, TaggedString *source) { static void init_state (LexState *ls, FuncState *fs, TString *source) {
lua_State *L = ls->L; lua_State *L = ls->L;
TProtoFunc *f = luaF_newproto(ls->L); Proto *f = luaF_newproto(ls->L);
fs->prev = ls->fs; /* linked list of funcstates */ fs->prev = ls->fs; /* linked list of funcstates */
ls->fs = fs; ls->fs = fs;
fs->stacksize = 0; fs->stacksize = 0;
@@ -340,19 +340,19 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *source) {
fs->nvars = (L->debug) ? 0 : -1; /* flag no debug information? */ fs->nvars = (L->debug) ? 0 : -1; /* flag no debug information? */
/* push function (to avoid GC) */ /* push function (to avoid GC) */
tfvalue(L->top) = f; tfvalue(L->top) = f;
ttype(L->top) = LUA_T_LPROTO; ttype(L->top) = TAG_LPROTO;
incr_top; incr_top;
} }
static void close_func (LexState *ls) { static void close_func (LexState *ls) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
TProtoFunc *f = fs->f; Proto *f = fs->f;
luaK_0(ls, ENDCODE, 0); luaK_0(ls, OP_END, 0);
luaM_reallocvector(ls->L, f->code, fs->pc, Instruction); luaM_reallocvector(ls->L, f->code, fs->pc, Instruction);
luaM_reallocvector(ls->L, f->kstr, f->nkstr, TaggedString *); luaM_reallocvector(ls->L, f->kstr, f->nkstr, TString *);
luaM_reallocvector(ls->L, f->knum, f->nknum, real); luaM_reallocvector(ls->L, f->knum, f->nknum, Number);
luaM_reallocvector(ls->L, f->kproto, f->nkproto, TProtoFunc *); luaM_reallocvector(ls->L, f->kproto, f->nkproto, Proto *);
if (fs->nvars != -1) { /* debug information? */ if (fs->nvars != -1) { /* debug information? */
luaI_registerlocalvar(ls, NULL, -1); /* flag end of vector */ luaI_registerlocalvar(ls, NULL, -1); /* flag end of vector */
luaM_reallocvector(ls->L, f->locvars, fs->nvars, LocVar); luaM_reallocvector(ls->L, f->locvars, fs->nvars, LocVar);
@@ -362,14 +362,14 @@ static void close_func (LexState *ls) {
} }
TProtoFunc *luaY_parser (lua_State *L, ZIO *z) { Proto *luaY_parser (lua_State *L, ZIO *z) {
struct LexState lexstate; struct LexState lexstate;
struct FuncState funcstate; struct FuncState funcstate;
luaX_setinput(L, &lexstate, z); luaX_setinput(L, &lexstate, z);
init_state(&lexstate, &funcstate, luaS_new(L, zname(z))); init_state(&lexstate, &funcstate, luaS_new(L, zname(z)));
next(&lexstate); /* read first token */ next(&lexstate); /* read first token */
chunk(&lexstate); chunk(&lexstate);
if (lexstate.token != EOS) if (lexstate.token != TK_EOS)
luaK_error(&lexstate, "<eof> expected"); luaK_error(&lexstate, "<eof> expected");
close_func(&lexstate); close_func(&lexstate);
return funcstate.f; return funcstate.f;
@@ -401,8 +401,8 @@ static int explist1 (LexState *ls) {
static int explist (LexState *ls) { static int explist (LexState *ls) {
/* explist -> [ explist1 ] */ /* explist -> [ explist1 ] */
switch (ls->token) { switch (ls->token) {
case ELSE: case ELSEIF: case END: case UNTIL: case TK_ELSE: case TK_ELSEIF: case TK_END: case TK_UNTIL:
case EOS: case ';': case ')': case TK_EOS: case ';': case ')':
return 0; /* empty list */ return 0; /* empty list */
default: default:
@@ -432,7 +432,7 @@ static void funcargs (LexState *ls, int slf) {
constructor(ls); constructor(ls);
break; break;
case STRING: /* funcargs -> STRING */ case TK_STRING: /* funcargs -> STRING */
code_string(ls, ls->seminfo.ts); /* must use `seminfo' before `next' */ code_string(ls, ls->seminfo.ts); /* must use `seminfo' before `next' */
next(ls); next(ls);
break; break;
@@ -442,7 +442,7 @@ static void funcargs (LexState *ls, int slf) {
break; break;
} }
fs->stacksize = slevel; /* call will remove function and arguments */ fs->stacksize = slevel; /* call will remove function and arguments */
luaK_AB(ls, CALL, slevel, MULT_RET, 0); luaK_AB(ls, OP_CALL, slevel, MULT_RET, 0);
} }
@@ -469,14 +469,14 @@ static void var_or_func_tail (LexState *ls, expdesc *v) {
next(ls); next(ls);
name = checkname(ls); name = checkname(ls);
luaK_tostack(ls, v, 1); /* `v' must be on stack */ luaK_tostack(ls, v, 1); /* `v' must be on stack */
luaK_U(ls, PUSHSELF, name, 1); luaK_U(ls, OP_PUSHSELF, name, 1);
funcargs(ls, 1); funcargs(ls, 1);
v->k = VEXP; v->k = VEXP;
v->u.l.t = v->u.l.f = 0; v->u.l.t = v->u.l.f = 0;
break; break;
} }
case '(': case STRING: case '{': /* var_or_func_tail -> funcargs */ case '(': case TK_STRING: case '{': /* var_or_func_tail -> funcargs */
luaK_tostack(ls, v, 1); /* `v' must be on stack */ luaK_tostack(ls, v, 1); /* `v' must be on stack */
funcargs(ls, 0); funcargs(ls, 0);
v->k = VEXP; v->k = VEXP;
@@ -513,7 +513,7 @@ static void var_or_func (LexState *ls, expdesc *v) {
static void recfield (LexState *ls) { static void recfield (LexState *ls) {
/* recfield -> (NAME | '['exp1']') = exp1 */ /* recfield -> (NAME | '['exp1']') = exp1 */
switch (ls->token) { switch (ls->token) {
case NAME: case TK_NAME:
luaK_kstr(ls, checkname(ls)); luaK_kstr(ls, checkname(ls));
break; break;
@@ -541,12 +541,12 @@ static int recfields (LexState *ls) {
recfield(ls); recfield(ls);
n++; n++;
if (++mod_n == RFIELDS_PER_FLUSH) { if (++mod_n == RFIELDS_PER_FLUSH) {
luaK_U(ls, SETMAP, RFIELDS_PER_FLUSH-1, -2*RFIELDS_PER_FLUSH); luaK_U(ls, OP_SETMAP, RFIELDS_PER_FLUSH-1, -2*RFIELDS_PER_FLUSH);
mod_n = 0; mod_n = 0;
} }
} }
if (mod_n) if (mod_n)
luaK_U(ls, SETMAP, mod_n-1, -2*mod_n); luaK_U(ls, OP_SETMAP, mod_n-1, -2*mod_n);
return n; return n;
} }
@@ -564,13 +564,13 @@ static int listfields (LexState *ls) {
checklimit(ls, n, MAXARG_A*LFIELDS_PER_FLUSH, checklimit(ls, n, MAXARG_A*LFIELDS_PER_FLUSH,
"items in a list initializer"); "items in a list initializer");
if (++mod_n == LFIELDS_PER_FLUSH) { if (++mod_n == LFIELDS_PER_FLUSH) {
luaK_AB(ls, SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH-1, luaK_AB(ls, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH-1,
-LFIELDS_PER_FLUSH); -LFIELDS_PER_FLUSH);
mod_n = 0; mod_n = 0;
} }
} }
if (mod_n > 0) if (mod_n > 0)
luaK_AB(ls, SETLIST, n/LFIELDS_PER_FLUSH, mod_n-1, -mod_n); luaK_AB(ls, OP_SETLIST, n/LFIELDS_PER_FLUSH, mod_n-1, -mod_n);
return n; return n;
} }
@@ -583,7 +583,7 @@ static void constructor_part (LexState *ls, constdesc *cd) {
cd->k = ls->token; cd->k = ls->token;
return; return;
case NAME: { case TK_NAME: {
expdesc v; expdesc v;
expr(ls, &v); expr(ls, &v);
if (ls->token == '=') { if (ls->token == '=') {
@@ -619,7 +619,7 @@ static void constructor_part (LexState *ls, constdesc *cd) {
static void constructor (LexState *ls) { static void constructor (LexState *ls) {
/* constructor -> '{' constructor_part [';' constructor_part] '}' */ /* constructor -> '{' constructor_part [';' constructor_part] '}' */
int line = ls->linenumber; int line = ls->linenumber;
int pc = luaK_U(ls, CREATETABLE, 0, 1); int pc = luaK_U(ls, OP_CREATETABLE, 0, 1);
int nelems; int nelems;
constdesc cd; constdesc cd;
check(ls, '{'); check(ls, '{');
@@ -653,19 +653,19 @@ static void constructor (LexState *ls) {
static void simpleexp (LexState *ls, expdesc *v) { static void simpleexp (LexState *ls, expdesc *v) {
check_debugline(ls); check_debugline(ls);
switch (ls->token) { switch (ls->token) {
case NUMBER: { /* simpleexp -> NUMBER */ case TK_NUMBER: { /* simpleexp -> NUMBER */
real r = ls->seminfo.r; Number r = ls->seminfo.r;
next(ls); next(ls);
luaK_number(ls, r); luaK_number(ls, r);
break; break;
} }
case STRING: /* simpleexp -> STRING */ case TK_STRING: /* simpleexp -> STRING */
code_string(ls, ls->seminfo.ts); /* must use `seminfo' before `next' */ code_string(ls, ls->seminfo.ts); /* must use `seminfo' before `next' */
next(ls); next(ls);
break; break;
case NIL: /* simpleexp -> NIL */ case TK_NIL: /* simpleexp -> NIL */
luaK_adjuststack(ls, -1); luaK_adjuststack(ls, -1);
next(ls); next(ls);
break; break;
@@ -674,7 +674,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
constructor(ls); constructor(ls);
break; break;
case FUNCTION: /* simpleexp -> FUNCTION body */ case TK_FUNCTION: /* simpleexp -> FUNCTION body */
next(ls); next(ls);
body(ls, 0, ls->linenumber); body(ls, 0, ls->linenumber);
break; break;
@@ -685,7 +685,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
check(ls, ')'); check(ls, ')');
return; return;
case NAME: case '%': case TK_NAME: case '%':
var_or_func(ls, v); var_or_func(ls, v);
return; return;
@@ -720,12 +720,12 @@ static int get_priority (int op, int *rp) {
case '+': case '-': *rp = 5; return 5; case '+': case '-': *rp = 5; return 5;
case CONC: *rp = 3; return 4; /* right associative (?) */ case TK_CONC: *rp = 3; return 4; /* right associative (?) */
case EQ: case NE: case '>': case '<': case LE: case GE: case TK_EQ: case TK_NE: case '>': case '<': case TK_LE: case TK_GE:
*rp = 2; return 2; *rp = 2; return 2;
case AND: case OR: *rp = 1; return 1; case TK_AND: case TK_OR: *rp = 1; return 1;
default: *rp = -1; return -1; default: *rp = -1; return -1;
} }
@@ -738,7 +738,7 @@ static int get_priority (int op, int *rp) {
*/ */
static void subexpr (LexState *ls, expdesc *v, int limit) { static void subexpr (LexState *ls, expdesc *v, int limit) {
int rp; int rp;
if (ls->token == '-' || ls->token == NOT) { if (ls->token == '-' || ls->token == TK_NOT) {
int op = ls->token; /* operator */ int op = ls->token; /* operator */
next(ls); next(ls);
subexpr(ls, v, UNARY_PRIORITY); subexpr(ls, v, UNARY_PRIORITY);
@@ -806,7 +806,7 @@ static int assignment (LexState *ls, expdesc *v, int nvars) {
luaK_storevar(ls, v); luaK_storevar(ls, v);
} }
else { /* indexed var with values in between*/ else { /* indexed var with values in between*/
luaK_U(ls, SETTABLE, left+(nvars-1), -1); luaK_U(ls, OP_SETTABLE, left+(nvars-1), -1);
left += 2; /* table&index are not popped, because they aren't on top */ left += 2; /* table&index are not popped, because they aren't on top */
} }
return left; return left;
@@ -838,11 +838,11 @@ static void whilestat (LexState *ls, int line) {
for (i=0; i<cond_size; i++) buffer[i] = fs->f->code[while_init+i]; for (i=0; i<cond_size; i++) buffer[i] = fs->f->code[while_init+i];
/* go back to state prior condition */ /* go back to state prior condition */
fs->pc = while_init; fs->pc = while_init;
luaK_S(ls, JMP, 0, 0); /* initial jump to condition */ luaK_S(ls, OP_JMP, 0, 0); /* initial jump to condition */
check(ls, DO); check(ls, TK_DO);
loopentry = luaK_getlabel(ls); loopentry = luaK_getlabel(ls);
block(ls); block(ls);
check_match(ls, END, WHILE, line); check_match(ls, TK_END, TK_WHILE, line);
cond_init = luaK_getlabel(ls); cond_init = luaK_getlabel(ls);
luaK_fixjump(ls, while_init, cond_init); luaK_fixjump(ls, while_init, cond_init);
/* correct `v' and copy condition to new position */ /* correct `v' and copy condition to new position */
@@ -859,7 +859,7 @@ static void repeatstat (LexState *ls, int line) {
expdesc v; expdesc v;
next(ls); next(ls);
block(ls); block(ls);
check_match(ls, UNTIL, REPEAT, line); check_match(ls, TK_UNTIL, TK_REPEAT, line);
expr(ls, &v); expr(ls, &v);
luaK_goiftrue(ls, &v, 0); luaK_goiftrue(ls, &v, 0);
luaK_patchlist(ls, v.u.l.f, repeat_init); luaK_patchlist(ls, v.u.l.f, repeat_init);
@@ -958,16 +958,16 @@ static void ifpart (LexState *ls, int line) {
next(ls); /* skip IF or ELSEIF */ next(ls); /* skip IF or ELSEIF */
expr(ls, &v); /* cond */ expr(ls, &v); /* cond */
luaK_goiftrue(ls, &v, 0); luaK_goiftrue(ls, &v, 0);
check(ls, THEN); check(ls, TK_THEN);
block(ls); /* `then' part */ block(ls); /* `then' part */
luaK_S(ls, JMP, 0, 0); /* 2nd jump: over `else' part */ luaK_S(ls, OP_JMP, 0, 0); /* 2nd jump: over `else' part */
elseinit = luaK_getlabel(ls); /* address of 2nd jump == elseinit-1 */ elseinit = luaK_getlabel(ls); /* address of 2nd jump == elseinit-1 */
if (ls->token == ELSEIF) if (ls->token == TK_ELSEIF)
ifpart(ls, line); ifpart(ls, line);
else { else {
if (optional(ls, ELSE)) if (optional(ls, TK_ELSE))
block(ls); /* `else' part */ block(ls); /* `else' part */
check_match(ls, END, IF, line); check_match(ls, TK_END, TK_IF, line);
} }
if (fs->pc > elseinit) { /* is there an `else' part? */ if (fs->pc > elseinit) { /* is there an `else' part? */
luaK_fixjump(ls, elseinit-1, luaK_getlabel(ls)); /* fix 2nd jump */ luaK_fixjump(ls, elseinit-1, luaK_getlabel(ls)); /* fix 2nd jump */
@@ -983,38 +983,38 @@ static void ifpart (LexState *ls, int line) {
static int stat (LexState *ls) { static int stat (LexState *ls) {
int line = ls->linenumber; /* may be needed for error messages */ int line = ls->linenumber; /* may be needed for error messages */
switch (ls->token) { switch (ls->token) {
case IF: /* stat -> IF ifpart END */ case TK_IF: /* stat -> IF ifpart END */
ifpart(ls, line); ifpart(ls, line);
return 1; return 1;
case WHILE: /* stat -> whilestat */ case TK_WHILE: /* stat -> whilestat */
whilestat(ls, line); whilestat(ls, line);
return 1; return 1;
case DO: { /* stat -> DO block END */ case TK_DO: { /* stat -> DO block END */
next(ls); next(ls);
block(ls); block(ls);
check_match(ls, END, DO, line); check_match(ls, TK_END, TK_DO, line);
return 1; return 1;
} }
case REPEAT: /* stat -> repeatstat */ case TK_REPEAT: /* stat -> repeatstat */
repeatstat(ls, line); repeatstat(ls, line);
return 1; return 1;
case FUNCTION: /* stat -> funcstat */ case TK_FUNCTION: /* stat -> funcstat */
return funcstat(ls, line); return funcstat(ls, line);
case LOCAL: /* stat -> localstat */ case TK_LOCAL: /* stat -> localstat */
localstat(ls); localstat(ls);
return 1; return 1;
case NAME: case '%': /* stat -> namestat */ case TK_NAME: case '%': /* stat -> namestat */
namestat(ls); namestat(ls);
return 1; return 1;
case RETURN: case ';': case ELSE: case ELSEIF: case TK_RETURN: case ';': case TK_ELSE: case TK_ELSEIF:
case END: case UNTIL: case EOS: /* `stat' follow */ case TK_END: case TK_UNTIL: case TK_EOS: /* `stat' follow */
return 0; return 0;
default: default:
@@ -1028,23 +1028,23 @@ static void parlist (LexState *ls) {
int nparams = 0; int nparams = 0;
int dots = 0; int dots = 0;
switch (ls->token) { switch (ls->token) {
case DOTS: /* parlist -> DOTS */ case TK_DOTS: /* parlist -> DOTS */
next(ls); next(ls);
dots = 1; dots = 1;
break; break;
case NAME: /* parlist, tailparlist -> NAME [',' tailparlist] */ case TK_NAME: /* parlist, tailparlist -> NAME [',' tailparlist] */
init: init:
store_localvar(ls, str_checkname(ls), nparams++); store_localvar(ls, str_checkname(ls), nparams++);
if (ls->token == ',') { if (ls->token == ',') {
next(ls); next(ls);
switch (ls->token) { switch (ls->token) {
case DOTS: /* tailparlist -> DOTS */ case TK_DOTS: /* tailparlist -> DOTS */
next(ls); next(ls);
dots = 1; dots = 1;
break; break;
case NAME: /* tailparlist -> NAME [',' tailparlist] */ case TK_NAME: /* tailparlist -> NAME [',' tailparlist] */
goto init; goto init;
default: luaK_error(ls, "<name> or `...' expected"); default: luaK_error(ls, "<name> or `...' expected");
@@ -1071,7 +1071,7 @@ static void body (LexState *ls, int needself, int line) {
parlist(ls); parlist(ls);
check(ls, ')'); check(ls, ')');
chunk(ls); chunk(ls);
check_match(ls, END, FUNCTION, line); check_match(ls, TK_END, TK_FUNCTION, line);
close_func(ls); close_func(ls);
func_onstack(ls, &new_fs); func_onstack(ls, &new_fs);
} }
@@ -1079,7 +1079,7 @@ static void body (LexState *ls, int needself, int line) {
static void ret (LexState *ls) { static void ret (LexState *ls) {
/* ret -> [RETURN explist sc] */ /* ret -> [RETURN explist sc] */
if (ls->token == RETURN) { if (ls->token == TK_RETURN) {
int nexps; /* number of expressions returned */ int nexps; /* number of expressions returned */
check_debugline(ls); check_debugline(ls);
next(ls); next(ls);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lparser.h,v 1.9 2000/03/03 18:53:17 roberto Exp roberto $ ** $Id: lparser.h,v 1.11 2000/03/09 13:57:37 roberto Exp roberto $
** LL(1) Parser and code generator for Lua ** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -68,7 +68,7 @@ typedef struct expdesc {
/* state needed to generate code for a given function */ /* state needed to generate code for a given function */
typedef struct FuncState { typedef struct FuncState {
TProtoFunc *f; /* current function header */ Proto *f; /* current function header */
struct FuncState *prev; /* enclosing function */ struct FuncState *prev; /* enclosing function */
int pc; /* next position to code */ int pc; /* next position to code */
int lasttarget; /* `pc' of last `jump target' */ int lasttarget; /* `pc' of last `jump target' */
@@ -78,11 +78,11 @@ typedef struct FuncState {
int nvars; /* number of entries in f->locvars (-1 if no debug information) */ int nvars; /* number of entries in f->locvars (-1 if no debug information) */
int lastsetline; /* line where last SETLINE was issued */ int lastsetline; /* line where last SETLINE was issued */
expdesc upvalues[MAXUPVALUES]; /* upvalues */ expdesc upvalues[MAXUPVALUES]; /* upvalues */
TaggedString *localvar[MAXLOCALS]; /* store local variable names */ TString *localvar[MAXLOCALS]; /* store local variable names */
} FuncState; } FuncState;
TProtoFunc *luaY_parser (lua_State *L, ZIO *z); Proto *luaY_parser (lua_State *L, ZIO *z);
#endif #endif

12
lref.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lref.c,v 1.7 2000/02/08 16:34:31 roberto Exp roberto $ ** $Id: lref.c,v 1.8 2000/03/03 14:58:26 roberto Exp roberto $
** reference mechanism ** reference mechanism
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -17,7 +17,7 @@
int lua_ref (lua_State *L, int lock) { int lua_ref (lua_State *L, int lock) {
int ref; int ref;
luaA_checkCargs(L, 1); luaA_checkCargs(L, 1);
if (ttype(L->top-1) == LUA_T_NIL) if (ttype(L->top-1) == TAG_NIL)
ref = LUA_REFNIL; ref = LUA_REFNIL;
else { else {
if (L->refFree != NONEXT) { /* is there a free place? */ if (L->refFree != NONEXT) { /* is there a free place? */
@@ -82,13 +82,13 @@ void lua_endblock (lua_State *L) {
static int ismarked (const TObject *o) { static int ismarked (const TObject *o) {
/* valid only for locked objects */ /* valid only for locked objects */
switch (o->ttype) { switch (o->ttype) {
case LUA_T_STRING: case LUA_T_USERDATA: case TAG_STRING: case TAG_USERDATA:
return o->value.ts->marked; return o->value.ts->marked;
case LUA_T_ARRAY: case TAG_ARRAY:
return o->value.a->marked; return o->value.a->marked;
case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: case TAG_LCLOSURE: case TAG_CCLOSURE:
return o->value.cl->marked; return o->value.cl->marked;
case LUA_T_LPROTO: case TAG_LPROTO:
return o->value.tf->marked; return o->value.tf->marked;
default: /* number or cproto */ default: /* number or cproto */
return 1; return 1;

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstate.h,v 1.28 2000/01/19 12:00:45 roberto Exp roberto $ ** $Id: lstate.h,v 1.29 2000/02/08 16:34:31 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -43,7 +43,7 @@ struct C_Lua_Stack {
typedef struct stringtable { typedef struct stringtable {
int size; int size;
int nuse; /* number of elements (including EMPTYs) */ int nuse; /* number of elements (including EMPTYs) */
TaggedString **hash; TString **hash;
} stringtable; } stringtable;
@@ -63,7 +63,7 @@ struct lua_State {
struct C_Lua_Stack *Cblocks; struct C_Lua_Stack *Cblocks;
int numCblocks; /* number of nested Cblocks */ int numCblocks; /* number of nested Cblocks */
/* global state */ /* global state */
TProtoFunc *rootproto; /* list of all prototypes */ Proto *rootproto; /* list of all prototypes */
Closure *rootcl; /* list of all closures */ Closure *rootcl; /* list of all closures */
Hash *roottable; /* list of all tables */ Hash *roottable; /* list of all tables */
GlobalVar *rootglobal; /* list of global variables */ GlobalVar *rootglobal; /* list of global variables */

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstring.c,v 1.32 2000/03/03 14:58:26 roberto Exp roberto $ ** $Id: lstring.c,v 1.33 2000/03/10 14:38:10 roberto Exp roberto $
** String table (keeps all strings handled by Lua) ** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -17,7 +17,7 @@
#define gcsizestring(L, l) numblocks(L, 0, sizeof(TaggedString)+l) #define gcsizestring(L, l) numblocks(L, 0, sizeof(TString)+l)
#define gcsizeudata gcsizestring(L, 0) #define gcsizeudata gcsizestring(L, 0)
@@ -28,7 +28,7 @@ void luaS_init (lua_State *L) {
for (i=0; i<NUM_HASHS; i++) { for (i=0; i<NUM_HASHS; i++) {
L->string_root[i].size = 1; L->string_root[i].size = 1;
L->string_root[i].nuse = 0; L->string_root[i].nuse = 0;
L->string_root[i].hash = luaM_newvector(L, 1, TaggedString *);; L->string_root[i].hash = luaM_newvector(L, 1, TString *);;
L->string_root[i].hash[0] = NULL; L->string_root[i].hash[0] = NULL;
} }
} }
@@ -54,14 +54,14 @@ static unsigned long hash_s (const char *s, long l) {
void luaS_resize (lua_State *L, stringtable *tb, int newsize) { void luaS_resize (lua_State *L, stringtable *tb, int newsize) {
TaggedString **newhash = luaM_newvector(L, newsize, TaggedString *); TString **newhash = luaM_newvector(L, newsize, TString *);
int i; int i;
for (i=0; i<newsize; i++) newhash[i] = NULL; for (i=0; i<newsize; i++) newhash[i] = NULL;
/* rehash */ /* rehash */
for (i=0; i<tb->size; i++) { for (i=0; i<tb->size; i++) {
TaggedString *p = tb->hash[i]; TString *p = tb->hash[i];
while (p) { /* for each node in the list */ while (p) { /* for each node in the list */
TaggedString *next = p->nexthash; /* save next */ TString *next = p->nexthash; /* save next */
int h = p->hash&(newsize-1); /* new position */ int h = p->hash&(newsize-1); /* new position */
LUA_ASSERT(L, p->hash%newsize == (p->hash&(newsize-1)), LUA_ASSERT(L, p->hash%newsize == (p->hash&(newsize-1)),
"a&(x-1) == a%x, for x power of 2"); "a&(x-1) == a%x, for x power of 2");
@@ -76,9 +76,9 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) {
} }
static TaggedString *newone (lua_State *L, long l, unsigned long h) { static TString *newone (lua_State *L, long l, unsigned long h) {
TaggedString *ts = (TaggedString *)luaM_malloc(L, TString *ts = (TString *)luaM_malloc(L,
sizeof(TaggedString)+l*sizeof(char)); sizeof(TString)+l*sizeof(char));
ts->marked = 0; ts->marked = 0;
ts->nexthash = NULL; ts->nexthash = NULL;
ts->hash = h; ts->hash = h;
@@ -86,9 +86,9 @@ static TaggedString *newone (lua_State *L, long l, unsigned long h) {
} }
static TaggedString *newone_s (lua_State *L, const char *str, static TString *newone_s (lua_State *L, const char *str,
long l, unsigned long h) { long l, unsigned long h) {
TaggedString *ts = newone(L, l, h); TString *ts = newone(L, l, h);
memcpy(ts->str, str, l); memcpy(ts->str, str, l);
ts->str[l] = 0; /* ending 0 */ ts->str[l] = 0; /* ending 0 */
ts->u.s.gv = NULL; /* no global value */ ts->u.s.gv = NULL; /* no global value */
@@ -99,9 +99,9 @@ static TaggedString *newone_s (lua_State *L, const char *str,
} }
static TaggedString *newone_u (lua_State *L, void *buff, static TString *newone_u (lua_State *L, void *buff,
int tag, unsigned long h) { int tag, unsigned long h) {
TaggedString *ts = newone(L, 0, h); TString *ts = newone(L, 0, h);
ts->u.d.value = buff; ts->u.d.value = buff;
ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag; ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag;
ts->constindex = -1; /* tag -> this is a userdata */ ts->constindex = -1; /* tag -> this is a userdata */
@@ -110,7 +110,7 @@ static TaggedString *newone_u (lua_State *L, void *buff,
} }
static void newentry (lua_State *L, stringtable *tb, TaggedString *ts, int h) { static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) {
ts->nexthash = tb->hash[h]; /* chain new entry */ ts->nexthash = tb->hash[h]; /* chain new entry */
tb->hash[h] = ts; tb->hash[h] = ts;
tb->nuse++; tb->nuse++;
@@ -119,12 +119,12 @@ static void newentry (lua_State *L, stringtable *tb, TaggedString *ts, int h) {
} }
TaggedString *luaS_newlstr (lua_State *L, const char *str, long l) { TString *luaS_newlstr (lua_State *L, const char *str, long l) {
unsigned long h = hash_s(str, l); unsigned long h = hash_s(str, l);
stringtable *tb = &L->string_root[(l==0) ? 0 : stringtable *tb = &L->string_root[(l==0) ? 0 :
((unsigned int)(str[0]+str[l-1]))&(NUM_HASHSTR-1)]; ((unsigned int)(str[0]+str[l-1]))&(NUM_HASHSTR-1)];
int h1 = h&(tb->size-1); int h1 = h&(tb->size-1);
TaggedString *ts; TString *ts;
for (ts = tb->hash[h1]; ts; ts = ts->nexthash) { for (ts = tb->hash[h1]; ts; ts = ts->nexthash) {
if (ts->u.s.len == l && (memcmp(str, ts->str, l) == 0)) if (ts->u.s.len == l && (memcmp(str, ts->str, l) == 0))
return ts; return ts;
@@ -140,11 +140,11 @@ TaggedString *luaS_newlstr (lua_State *L, const char *str, long l) {
** uses '%' for one hashing with userdata because addresses are too regular, ** uses '%' for one hashing with userdata because addresses are too regular,
** so two '&' operations would be highly correlated ** so two '&' operations would be highly correlated
*/ */
TaggedString *luaS_createudata (lua_State *L, void *udata, int tag) { TString *luaS_createudata (lua_State *L, void *udata, int tag) {
unsigned long h = IntPoint(L, udata); unsigned long h = IntPoint(L, udata);
stringtable *tb = &L->string_root[(h%NUM_HASHUDATA)+NUM_HASHSTR]; stringtable *tb = &L->string_root[(h%NUM_HASHUDATA)+NUM_HASHSTR];
int h1 = h&(tb->size-1); int h1 = h&(tb->size-1);
TaggedString *ts; TString *ts;
for (ts = tb->hash[h1]; ts; ts = ts->nexthash) { for (ts = tb->hash[h1]; ts; ts = ts->nexthash) {
if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG)) if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG))
return ts; return ts;
@@ -156,18 +156,18 @@ TaggedString *luaS_createudata (lua_State *L, void *udata, int tag) {
} }
TaggedString *luaS_new (lua_State *L, const char *str) { TString *luaS_new (lua_State *L, const char *str) {
return luaS_newlstr(L, str, strlen(str)); return luaS_newlstr(L, str, strlen(str));
} }
TaggedString *luaS_newfixed (lua_State *L, const char *str) { TString *luaS_newfixed (lua_State *L, const char *str) {
TaggedString *ts = luaS_new(L, str); TString *ts = luaS_new(L, str);
if (ts->marked == 0) ts->marked = FIXMARK; /* avoid GC */ if (ts->marked == 0) ts->marked = FIXMARK; /* avoid GC */
return ts; return ts;
} }
void luaS_free (lua_State *L, TaggedString *t) { void luaS_free (lua_State *L, TString *t) {
if (t->constindex == -1) /* is userdata? */ if (t->constindex == -1) /* is userdata? */
L->nblocks -= gcsizeudata; L->nblocks -= gcsizeudata;
else { /* is string */ else { /* is string */
@@ -178,11 +178,11 @@ void luaS_free (lua_State *L, TaggedString *t) {
} }
GlobalVar *luaS_assertglobal (lua_State *L, TaggedString *ts) { GlobalVar *luaS_assertglobal (lua_State *L, TString *ts) {
GlobalVar *gv = ts->u.s.gv; GlobalVar *gv = ts->u.s.gv;
if (!gv) { /* no global value yet? */ if (!gv) { /* no global value yet? */
gv = luaM_new(L, GlobalVar); gv = luaM_new(L, GlobalVar);
gv->value.ttype = LUA_T_NIL; /* initial value */ gv->value.ttype = TAG_NIL; /* initial value */
gv->name = ts; gv->name = ts;
gv->next = L->rootglobal; /* chain in global list */ gv->next = L->rootglobal; /* chain in global list */
L->rootglobal = gv; L->rootglobal = gv;
@@ -198,8 +198,8 @@ GlobalVar *luaS_assertglobalbyname (lua_State *L, const char *name) {
int luaS_globaldefined (lua_State *L, const char *name) { int luaS_globaldefined (lua_State *L, const char *name) {
TaggedString *ts = luaS_new(L, name); TString *ts = luaS_new(L, name);
return ts->u.s.gv && ts->u.s.gv->value.ttype != LUA_T_NIL; return ts->u.s.gv && ts->u.s.gv->value.ttype != TAG_NIL;
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstring.h,v 1.16 2000/03/03 14:58:26 roberto Exp roberto $ ** $Id: lstring.h,v 1.17 2000/03/10 14:38:10 roberto Exp roberto $
** String table (keep all strings handled by Lua) ** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -27,13 +27,13 @@
void luaS_init (lua_State *L); void luaS_init (lua_State *L);
void luaS_resize (lua_State *L, stringtable *tb, int newsize); void luaS_resize (lua_State *L, stringtable *tb, int newsize);
TaggedString *luaS_createudata (lua_State *L, void *udata, int tag); TString *luaS_createudata (lua_State *L, void *udata, int tag);
void luaS_freeall (lua_State *L); void luaS_freeall (lua_State *L);
void luaS_free (lua_State *L, TaggedString *ts); void luaS_free (lua_State *L, TString *ts);
TaggedString *luaS_newlstr (lua_State *L, const char *str, long l); TString *luaS_newlstr (lua_State *L, const char *str, long l);
TaggedString *luaS_new (lua_State *L, const char *str); TString *luaS_new (lua_State *L, const char *str);
TaggedString *luaS_newfixed (lua_State *L, const char *str); TString *luaS_newfixed (lua_State *L, const char *str);
GlobalVar *luaS_assertglobal (lua_State *L, TaggedString *ts); GlobalVar *luaS_assertglobal (lua_State *L, TString *ts);
GlobalVar *luaS_assertglobalbyname (lua_State *L, const char *name); GlobalVar *luaS_assertglobalbyname (lua_State *L, const char *name);
int luaS_globaldefined (lua_State *L, const char *name); int luaS_globaldefined (lua_State *L, const char *name);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltable.c,v 1.34 2000/02/08 16:34:31 roberto Exp roberto $ ** $Id: ltable.c,v 1.35 2000/03/03 14:58:26 roberto Exp roberto $
** Lua tables (hash) ** Lua tables (hash)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -32,7 +32,7 @@
#define TagDefault LUA_T_ARRAY #define TagDefault TAG_ARRAY
@@ -43,22 +43,22 @@
Node *luaH_mainposition (const Hash *t, const TObject *key) { Node *luaH_mainposition (const Hash *t, const TObject *key) {
unsigned long h; unsigned long h;
switch (ttype(key)) { switch (ttype(key)) {
case LUA_T_NUMBER: case TAG_NUMBER:
h = (unsigned long)(long)nvalue(key); h = (unsigned long)(long)nvalue(key);
break; break;
case LUA_T_STRING: case LUA_T_USERDATA: case TAG_STRING: case TAG_USERDATA:
h = tsvalue(key)->hash; h = tsvalue(key)->hash;
break; break;
case LUA_T_ARRAY: case TAG_ARRAY:
h = IntPoint(L, avalue(key)); h = IntPoint(L, avalue(key));
break; break;
case LUA_T_LPROTO: case TAG_LPROTO:
h = IntPoint(L, tfvalue(key)); h = IntPoint(L, tfvalue(key));
break; break;
case LUA_T_CPROTO: case TAG_CPROTO:
h = IntPoint(L, fvalue(key)); h = IntPoint(L, fvalue(key));
break; break;
case LUA_T_LCLOSURE: case LUA_T_CCLOSURE: case TAG_LCLOSURE: case TAG_CCLOSURE:
h = IntPoint(L, clvalue(key)); h = IntPoint(L, clvalue(key));
break; break;
default: default:
@@ -95,7 +95,7 @@ static Node *hashnodecreate (lua_State *L, int nhash) {
Node *v = luaM_newvector(L, nhash, Node); Node *v = luaM_newvector(L, nhash, Node);
int i; int i;
for (i=0; i<nhash; i++) { for (i=0; i<nhash; i++) {
ttype(&v[i].key) = ttype(&v[i].val) = LUA_T_NIL; ttype(&v[i].key) = ttype(&v[i].val) = TAG_NIL;
v[i].next = NULL; v[i].next = NULL;
} }
return v; return v;
@@ -134,7 +134,7 @@ static int newsize (const Hash *t) {
int realuse = 0; int realuse = 0;
int i; int i;
for (i=0; i<size; i++) { for (i=0; i<size; i++) {
if (ttype(&v[i].val) != LUA_T_NIL) if (ttype(&v[i].val) != TAG_NIL)
realuse++; realuse++;
} }
return luaO_power2(realuse+realuse/4+1); return luaO_power2(realuse+realuse/4+1);
@@ -149,7 +149,7 @@ static void rehash (lua_State *L, Hash *t) {
setnodevector(L, t, newsize(t)); /* create new array of nodes */ setnodevector(L, t, newsize(t)); /* create new array of nodes */
for (i=0; i<oldsize; i++) { for (i=0; i<oldsize; i++) {
Node *old = nold+i; Node *old = nold+i;
if (ttype(&old->val) != LUA_T_NIL) if (ttype(&old->val) != TAG_NIL)
luaH_set(L, t, &old->key, &old->val); luaH_set(L, t, &old->key, &old->val);
} }
luaM_free(L, nold); /* free old array */ luaM_free(L, nold); /* free old array */
@@ -182,7 +182,7 @@ void luaH_set (lua_State *L, Hash *t, const TObject *key, const TObject *val) {
else n = n->next; else n = n->next;
} while (n); } while (n);
/* `key' not found; must insert it */ /* `key' not found; must insert it */
if (ttype(&mp->key) != LUA_T_NIL) { /* main position is not free? */ if (ttype(&mp->key) != TAG_NIL) { /* main position is not free? */
Node *othern; /* main position of colliding node */ Node *othern; /* main position of colliding node */
n = t->firstfree; /* get a free place */ n = t->firstfree; /* get a free place */
/* is colliding node out of its main position? (can only happens if /* is colliding node out of its main position? (can only happens if
@@ -204,7 +204,7 @@ void luaH_set (lua_State *L, Hash *t, const TObject *key, const TObject *val) {
mp->key = *key; mp->key = *key;
mp->val = *val; mp->val = *val;
for (;;) { /* check free places */ for (;;) { /* check free places */
if (ttype(&(t->firstfree)->key) == LUA_T_NIL) if (ttype(&(t->firstfree)->key) == TAG_NIL)
return; /* OK; table still has a free place */ return; /* OK; table still has a free place */
else if (t->firstfree == t->node) break; /* cannot decrement from here */ else if (t->firstfree == t->node) break; /* cannot decrement from here */
else (t->firstfree)--; else (t->firstfree)--;
@@ -215,7 +215,7 @@ void luaH_set (lua_State *L, Hash *t, const TObject *key, const TObject *val) {
void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) { void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) {
TObject index; TObject index;
ttype(&index) = LUA_T_NUMBER; ttype(&index) = TAG_NUMBER;
nvalue(&index) = key; nvalue(&index) = key;
luaH_set(L, t, &index, val); luaH_set(L, t, &index, val);
} }
@@ -223,7 +223,7 @@ void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) {
const TObject *luaH_getint (lua_State *L, const Hash *t, int key) { const TObject *luaH_getint (lua_State *L, const Hash *t, int key) {
TObject index; TObject index;
ttype(&index) = LUA_T_NUMBER; ttype(&index) = TAG_NUMBER;
nvalue(&index) = key; nvalue(&index) = key;
return luaH_get(L, t, &index); return luaH_get(L, t, &index);
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltests.c,v 1.7 2000/02/08 16:34:31 roberto Exp roberto $ ** $Id: ltests.c,v 1.8 2000/02/21 18:30:06 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation ** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -39,7 +39,7 @@ static void mem_query (lua_State *L) {
static void hash_query (lua_State *L) { static void hash_query (lua_State *L) {
lua_Object o = luaL_nonnullarg(L, 1); lua_Object o = luaL_nonnullarg(L, 1);
if (lua_getparam(L, 2) == LUA_NOOBJECT) { if (lua_getparam(L, 2) == LUA_NOOBJECT) {
luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "string expected"); luaL_arg_check(L, ttype(o) == TAG_STRING, 1, "string expected");
lua_pushnumber(L, tsvalue(o)->hash); lua_pushnumber(L, tsvalue(o)->hash);
} }
else { else {
@@ -75,7 +75,7 @@ static void query_strings (lua_State *L) {
} }
} }
else { else {
TaggedString *ts = L->string_root[h].hash[s]; TString *ts = L->string_root[h].hash[s];
for (ts = L->string_root[h].hash[s]; ts; ts = ts->nexthash) { for (ts = L->string_root[h].hash[s]; ts; ts = ts->nexthash) {
if (ts->constindex == -1) lua_pushstring(L, "<USERDATA>"); if (ts->constindex == -1) lua_pushstring(L, "<USERDATA>");
else lua_pushstring(L, ts->str); else lua_pushstring(L, ts->str);

40
ltm.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltm.c,v 1.32 2000/02/22 18:12:46 roberto Exp roberto $ ** $Id: ltm.c,v 1.33 2000/03/03 14:58:26 roberto Exp roberto $
** Tag methods ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -32,33 +32,33 @@ static int luaI_checkevent (lua_State *L, const char *name, const char *const li
/* events in LUA_T_NIL are all allowed, since this is used as a /* events in TAG_NIL are all allowed, since this is used as a
* 'placeholder' for "default" fallbacks * 'placeholder' for "default" fallbacks
*/ */
/* ORDER LUA_T, ORDER IM */ /* ORDER LUA_T, ORDER IM */
static const char luaT_validevents[NUM_TAGS][IM_N] = { static const char luaT_validevents[NUM_TAGS][IM_N] = {
{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */ {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_USERDATA */
{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */ {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* TAG_NUMBER */
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* TAG_STRING */
{0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_ARRAY */ {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_ARRAY */
{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_LPROTO */ {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_LPROTO */
{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CPROTO */ {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_CPROTO */
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* TAG_NIL */
}; };
int luaT_validevent (int t, int e) { /* ORDER LUA_T */ int luaT_validevent (int t, int e) { /* ORDER LUA_T */
#ifdef LUA_COMPAT_GC #ifdef LUA_COMPAT_GC
if (t == LUA_T_ARRAY && e == IM_GC) if (t == TAG_ARRAY && e == IM_GC)
return 1; /* old versions allowed gc tag method for tables */ return 1; /* old versions allowed gc tag method for tables */
#endif #endif
return (t < LUA_T_NIL) ? 1 : luaT_validevents[-t][e]; return (t < TAG_NIL) ? 1 : luaT_validevents[-t][e];
} }
static void init_entry (lua_State *L, int tag) { static void init_entry (lua_State *L, int tag) {
int i; int i;
for (i=0; i<IM_N; i++) for (i=0; i<IM_N; i++)
ttype(luaT_getim(L, tag, i)) = LUA_T_NIL; ttype(luaT_getim(L, tag, i)) = TAG_NIL;
} }
@@ -85,7 +85,7 @@ static void checktag (lua_State *L, int tag) {
} }
void luaT_realtag (lua_State *L, int tag) { void luaT_realtag (lua_State *L, int tag) {
if (!(L->last_tag <= tag && tag < LUA_T_NIL)) if (!(L->last_tag <= tag && tag < TAG_NIL))
luaL_verror(L, "tag %d was not created by `newtag'", tag); luaL_verror(L, "tag %d was not created by `newtag'", tag);
} }
@@ -104,17 +104,17 @@ int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) {
int luaT_effectivetag (const TObject *o) { int luaT_effectivetag (const TObject *o) {
static const int realtag[] = { /* ORDER LUA_T */ static const int realtag[] = { /* ORDER LUA_T */
LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, TAG_USERDATA, TAG_NUMBER, TAG_STRING, TAG_ARRAY,
LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, TAG_LPROTO, TAG_CPROTO, TAG_NIL,
LUA_T_LPROTO, LUA_T_CPROTO, /* LUA_T_LCLOSURE, LUA_T_CCLOSURE */ TAG_LPROTO, TAG_CPROTO, /* TAG_LCLOSURE, TAG_CCLOSURE */
}; };
int t; int t;
switch (t = ttype(o)) { switch (t = ttype(o)) {
case LUA_T_USERDATA: { case TAG_USERDATA: {
int tag = o->value.ts->u.d.tag; int tag = o->value.ts->u.d.tag;
return (tag >= 0) ? LUA_T_USERDATA : tag; /* deprecated test */ return (tag >= 0) ? TAG_USERDATA : tag; /* deprecated test */
} }
case LUA_T_ARRAY: return o->value.a->htag; case TAG_ARRAY: return o->value.a->htag;
default: return realtag[-t]; default: return realtag[-t];
} }
} }
@@ -149,7 +149,7 @@ void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) {
if (!luaT_validevent(t, e)) if (!luaT_validevent(t, e))
luaL_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", luaL_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s",
luaT_eventname[e], luaO_typenames[-t], luaT_eventname[e], luaO_typenames[-t],
(t == LUA_T_ARRAY || t == LUA_T_USERDATA) ? " with default tag" (t == TAG_ARRAY || t == TAG_USERDATA) ? " with default tag"
: ""); : "");
temp = *func; temp = *func;
*func = *luaT_getim(L, t,e); *func = *luaT_getim(L, t,e);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lundump.c,v 1.26 2000/02/17 19:17:44 lhf Exp lhf $ ** $Id: lundump.c,v 1.18 2000/03/03 14:58:26 roberto Exp roberto $
** load bytecodes from files ** load bytecodes from files
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -50,7 +50,7 @@ static unsigned long LoadLong (lua_State* L, ZIO* Z)
return (hi<<16)|lo; return (hi<<16)|lo;
} }
static real LoadNumber (lua_State* L, ZIO* Z) static Number LoadNumber (lua_State* L, ZIO* Z)
{ {
char b[256]; char b[256];
int size=ezgetc(L,Z); int size=ezgetc(L,Z);
@@ -67,15 +67,15 @@ static int LoadInt (lua_State* L, ZIO* Z, const char* message)
return i; return i;
} }
static void LoadCode (lua_State* L, TProtoFunc* tf, ZIO* Z) static void LoadCode (lua_State* L, Proto* tf, ZIO* Z)
{ {
int size=LoadInt(L,Z,"code too long (%lu bytes) in %.255s"); int size=LoadInt(L,Z,"code too long (%lu bytes) in %.255s");
tf->code=luaM_newvector(L,size,Instruction); tf->code=luaM_newvector(L,size,Instruction);
LoadBlock(L,tf->code,size*sizeof(tf->code[0]),Z); LoadBlock(L,tf->code,size*sizeof(tf->code[0]),Z);
if (tf->code[size-1]!=ENDCODE) luaL_verror(L,"bad code in %.255s",zname(Z)); if (tf->code[size-1]!=OP_END) luaL_verror(L,"bad code in %.255s",zname(Z));
} }
static TaggedString* LoadString (lua_State* L, ZIO* Z) static TString* LoadString (lua_State* L, ZIO* Z)
{ {
long size=LoadLong(L,Z); long size=LoadLong(L,Z);
if (size==0) if (size==0)
@@ -88,7 +88,7 @@ static TaggedString* LoadString (lua_State* L, ZIO* Z)
} }
} }
static void LoadLocals (lua_State* L, TProtoFunc* tf, ZIO* Z) static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z)
{ {
int i,n=LoadInt(L,Z,"too many locals (%lu) in %.255s"); int i,n=LoadInt(L,Z,"too many locals (%lu) in %.255s");
if (n==0) return; if (n==0) return;
@@ -102,21 +102,21 @@ static void LoadLocals (lua_State* L, TProtoFunc* tf, ZIO* Z)
tf->locvars[i].varname=NULL; tf->locvars[i].varname=NULL;
} }
static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native); static Proto* LoadFunction (lua_State* L, ZIO* Z, int native);
static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native) static void LoadConstants (lua_State* L, Proto* tf, ZIO* Z, int native)
{ {
int i,n; int i,n;
tf->nkstr=n=LoadInt(L,Z,"too many strings (%lu) in %.255s"); tf->nkstr=n=LoadInt(L,Z,"too many strings (%lu) in %.255s");
if (n>0) if (n>0)
{ {
tf->kstr=luaM_newvector(L,n,TaggedString*); tf->kstr=luaM_newvector(L,n,TString*);
for (i=0; i<n; i++) tf->kstr[i]=LoadString(L,Z); for (i=0; i<n; i++) tf->kstr[i]=LoadString(L,Z);
} }
tf->nknum=n=LoadInt(L,Z,"too many numbers (%lu) in %.255s"); tf->nknum=n=LoadInt(L,Z,"too many numbers (%lu) in %.255s");
if (n>0) if (n>0)
{ {
tf->knum=luaM_newvector(L,n,real); tf->knum=luaM_newvector(L,n,Number);
if (native) if (native)
LoadBlock(L,tf->knum,n*sizeof(tf->knum[0]),Z); LoadBlock(L,tf->knum,n*sizeof(tf->knum[0]),Z);
else else
@@ -125,14 +125,14 @@ static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native)
tf->nkproto=n=LoadInt(L,Z,"too many functions (%lu) in %.255s"); tf->nkproto=n=LoadInt(L,Z,"too many functions (%lu) in %.255s");
if (n>0) if (n>0)
{ {
tf->kproto=luaM_newvector(L,n,TProtoFunc*); tf->kproto=luaM_newvector(L,n,Proto*);
for (i=0; i<n; i++) tf->kproto[i]=LoadFunction(L,Z,native); for (i=0; i<n; i++) tf->kproto[i]=LoadFunction(L,Z,native);
} }
} }
static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native) static Proto* LoadFunction (lua_State* L, ZIO* Z, int native)
{ {
TProtoFunc* tf=luaF_newproto(L); Proto* tf=luaF_newproto(L);
tf->lineDefined=LoadInt(L,Z,"lineDefined too large (%lu) in %.255s"); tf->lineDefined=LoadInt(L,Z,"lineDefined too large (%lu) in %.255s");
tf->source=LoadString(L,Z); tf->source=LoadString(L,Z);
if (tf->source==NULL) tf->source=luaS_new(L,zname(Z)); if (tf->source==NULL) tf->source=luaS_new(L,zname(Z));
@@ -172,12 +172,12 @@ static int LoadHeader (lua_State* L, ZIO* Z)
native=(sizeofR!=0); native=(sizeofR!=0);
if (native) /* test number representation */ if (native) /* test number representation */
{ {
if (sizeofR!=sizeof(real)) if (sizeofR!=sizeof(Number))
luaL_verror(L,"unknown number size in %.255s: read %d; expected %d", luaL_verror(L,"unknown number size in %.255s: read %d; expected %d",
zname(Z),sizeofR,(int)sizeof(real)); zname(Z),sizeofR,(int)sizeof(Number));
else else
{ {
real f=0,tf=TEST_NUMBER; Number f=0,tf=TEST_NUMBER;
LoadBlock(L,&f,sizeof(f),Z); LoadBlock(L,&f,sizeof(f),Z);
if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
luaL_verror(L,"unknown number format in %.255s: " luaL_verror(L,"unknown number format in %.255s: "
@@ -188,7 +188,7 @@ static int LoadHeader (lua_State* L, ZIO* Z)
return native; return native;
} }
static TProtoFunc* LoadChunk (lua_State* L, ZIO* Z) static Proto* LoadChunk (lua_State* L, ZIO* Z)
{ {
return LoadFunction(L,Z,LoadHeader(L,Z)); return LoadFunction(L,Z,LoadHeader(L,Z));
} }
@@ -197,7 +197,7 @@ static TProtoFunc* LoadChunk (lua_State* L, ZIO* Z)
** load one chunk from a file or buffer ** load one chunk from a file or buffer
** return main if ok and NULL at EOF ** return main if ok and NULL at EOF
*/ */
TProtoFunc* luaU_undump1 (lua_State* L, ZIO* Z) Proto* luaU_undump1 (lua_State* L, ZIO* Z)
{ {
int c=zgetc(Z); int c=zgetc(Z);
if (c==ID_CHUNK) if (c==ID_CHUNK)

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lundump.h,v 1.18 2000/01/28 17:51:09 lhf Exp $ ** $Id: lundump.h,v 1.13 2000/03/03 14:58:26 roberto Exp roberto $
** load pre-compiled Lua chunks ** load pre-compiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -11,11 +11,11 @@
#include "lzio.h" #include "lzio.h"
/* load one chunk */ /* load one chunk */
TProtoFunc* luaU_undump1 (lua_State* L, ZIO* Z); Proto* luaU_undump1 (lua_State* L, ZIO* Z);
/* handle cases that cannot happen */ /* handle cases that cannot happen */
void luaU_badconstant (lua_State* L, const char* s, int i, void luaU_badconstant (lua_State* L, const char* s, int i,
const TObject* o, const TProtoFunc* tf); const TObject* o, const Proto* tf);
/* convert number from text */ /* convert number from text */
double luaU_str2d (lua_State* L, const char* b, const char* where); double luaU_str2d (lua_State* L, const char* b, const char* where);

206
lvm.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 1.93 2000/03/09 13:57:37 roberto Exp roberto $ ** $Id: lvm.c,v 1.94 2000/03/10 14:38:10 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -33,32 +33,32 @@
/* /*
** Extra stack size to run a function: ** Extra stack size to run a function:
** LUA_T_LINE(1), NAME(1), TM calls(3) (plus some extra...) ** TAG_LINE(1), NAME(1), TM calls(3) (plus some extra...)
*/ */
#define EXTRA_STACK 8 #define EXTRA_STACK 8
int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */ int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
if (ttype(obj) != LUA_T_STRING) if (ttype(obj) != TAG_STRING)
return 1; return 1;
else { else {
if (!luaO_str2d(svalue(obj), &nvalue(obj))) if (!luaO_str2d(svalue(obj), &nvalue(obj)))
return 2; return 2;
ttype(obj) = LUA_T_NUMBER; ttype(obj) = TAG_NUMBER;
return 0; return 0;
} }
} }
int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */
if (ttype(obj) != LUA_T_NUMBER) if (ttype(obj) != TAG_NUMBER)
return 1; return 1;
else { else {
char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */
sprintf(s, "%.16g", (double)nvalue(obj)); sprintf(s, "%.16g", (double)nvalue(obj));
tsvalue(obj) = luaS_new(L, s); tsvalue(obj) = luaS_new(L, s);
ttype(obj) = LUA_T_STRING; ttype(obj) = TAG_STRING;
return 0; return 0;
} }
} }
@@ -66,8 +66,8 @@ int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */
void luaV_setn (lua_State *L, Hash *t, int val) { void luaV_setn (lua_State *L, Hash *t, int val) {
TObject index, value; TObject index, value;
ttype(&index) = LUA_T_STRING; tsvalue(&index) = luaS_new(L, "n"); ttype(&index) = TAG_STRING; tsvalue(&index) = luaS_new(L, "n");
ttype(&value) = LUA_T_NUMBER; nvalue(&value) = val; ttype(&value) = TAG_NUMBER; nvalue(&value) = val;
luaH_set(L, t, &index, &value); luaH_set(L, t, &index, &value);
} }
@@ -79,8 +79,8 @@ void luaV_closure (lua_State *L, int nelems) {
L->top -= nelems; L->top -= nelems;
while (nelems--) while (nelems--)
c->consts[nelems+1] = *(L->top-1+nelems); c->consts[nelems+1] = *(L->top-1+nelems);
ttype(L->top-1) = (ttype(&c->consts[0]) == LUA_T_CPROTO) ? ttype(L->top-1) = (ttype(&c->consts[0]) == TAG_CPROTO) ?
LUA_T_CCLOSURE : LUA_T_LCLOSURE; TAG_CCLOSURE : TAG_LCLOSURE;
(L->top-1)->value.cl = c; (L->top-1)->value.cl = c;
} }
} }
@@ -93,9 +93,9 @@ void luaV_closure (lua_State *L, int nelems) {
void luaV_gettable (lua_State *L, StkId top) { void luaV_gettable (lua_State *L, StkId top) {
TObject *table = top-2; TObject *table = top-2;
const TObject *im; const TObject *im;
if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable TM */ if (ttype(table) != TAG_ARRAY) { /* not a table, get gettable TM */
im = luaT_getimbyObj(L, table, IM_GETTABLE); im = luaT_getimbyObj(L, table, IM_GETTABLE);
if (ttype(im) == LUA_T_NIL) { if (ttype(im) == TAG_NIL) {
L->top = top; L->top = top;
luaG_indexerror(L, table); luaG_indexerror(L, table);
} }
@@ -103,10 +103,10 @@ void luaV_gettable (lua_State *L, StkId top) {
else { /* object is a table... */ else { /* object is a table... */
int tg = table->value.a->htag; int tg = table->value.a->htag;
im = luaT_getim(L, tg, IM_GETTABLE); im = luaT_getim(L, tg, IM_GETTABLE);
if (ttype(im) == LUA_T_NIL) { /* and does not have a `gettable' TM */ if (ttype(im) == TAG_NIL) { /* and does not have a `gettable' TM */
const TObject *h = luaH_get(L, avalue(table), table+1); const TObject *h = luaH_get(L, avalue(table), table+1);
if (ttype(h) == LUA_T_NIL && if (ttype(h) == TAG_NIL &&
(ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) { (ttype(im=luaT_getim(L, tg, IM_INDEX)) != TAG_NIL)) {
/* result is nil and there is an `index' tag method */ /* result is nil and there is an `index' tag method */
L->top = top; L->top = top;
luaD_callTM(L, im, 2, 1); /* calls it */ luaD_callTM(L, im, 2, 1); /* calls it */
@@ -128,15 +128,15 @@ void luaV_gettable (lua_State *L, StkId top) {
*/ */
void luaV_settable (lua_State *L, StkId t, StkId top) { void luaV_settable (lua_State *L, StkId t, StkId top) {
const TObject *im; const TObject *im;
if (ttype(t) != LUA_T_ARRAY) { /* not a table, get `settable' method */ if (ttype(t) != TAG_ARRAY) { /* not a table, get `settable' method */
L->top = top; L->top = top;
im = luaT_getimbyObj(L, t, IM_SETTABLE); im = luaT_getimbyObj(L, t, IM_SETTABLE);
if (ttype(im) == LUA_T_NIL) if (ttype(im) == TAG_NIL)
luaG_indexerror(L, t); luaG_indexerror(L, t);
} }
else { /* object is a table... */ else { /* object is a table... */
im = luaT_getim(L, avalue(t)->htag, IM_SETTABLE); im = luaT_getim(L, avalue(t)->htag, IM_SETTABLE);
if (ttype(im) == LUA_T_NIL) { /* and does not have a `settable' method */ if (ttype(im) == TAG_NIL) { /* and does not have a `settable' method */
luaH_set(L, avalue(t), t+1, top-1); luaH_set(L, avalue(t), t+1, top-1);
return; return;
} }
@@ -155,7 +155,7 @@ void luaV_settable (lua_State *L, StkId t, StkId top) {
void luaV_rawsettable (lua_State *L, StkId t) { void luaV_rawsettable (lua_State *L, StkId t) {
if (ttype(t) != LUA_T_ARRAY) if (ttype(t) != TAG_ARRAY)
lua_error(L, "indexed expression not a table"); lua_error(L, "indexed expression not a table");
else { else {
luaH_set(L, avalue(t), t+1, L->top-1); luaH_set(L, avalue(t), t+1, L->top-1);
@@ -167,12 +167,12 @@ void luaV_rawsettable (lua_State *L, StkId t) {
void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top) { void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top) {
const TObject *value = &gv->value; const TObject *value = &gv->value;
TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL); TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL);
if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ if (ttype(im) == TAG_NIL) /* is there a tag method? */
*top = *value; /* default behavior */ *top = *value; /* default behavior */
else { /* tag method */ else { /* tag method */
luaD_checkstack(L, 3); luaD_checkstack(L, 3);
*top = *im; *top = *im;
ttype(top+1) = LUA_T_STRING; ttype(top+1) = TAG_STRING;
tsvalue(top+1) = gv->name; /* global name */ tsvalue(top+1) = gv->name; /* global name */
*(top+2) = *value; *(top+2) = *value;
L->top = top+3; L->top = top+3;
@@ -184,13 +184,13 @@ void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top) {
void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top) { void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top) {
const TObject *oldvalue = &gv->value; const TObject *oldvalue = &gv->value;
const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL);
if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ if (ttype(im) == TAG_NIL) /* is there a tag method? */
gv->value = *(top-1); gv->value = *(top-1);
else { else {
luaD_checkstack(L, 3); luaD_checkstack(L, 3);
*(top+2) = *(top-1); /* new value */ *(top+2) = *(top-1); /* new value */
*(top+1) = *oldvalue; *(top+1) = *oldvalue;
ttype(top) = LUA_T_STRING; ttype(top) = TAG_STRING;
tsvalue(top) = gv->name; tsvalue(top) = gv->name;
*(top-1) = *im; *(top-1) = *im;
L->top = top+3; L->top = top+3;
@@ -203,11 +203,11 @@ static void call_binTM (lua_State *L, StkId top, IMS event, const char *msg) {
/* try first operand */ /* try first operand */
const TObject *im = luaT_getimbyObj(L, top-2, event); const TObject *im = luaT_getimbyObj(L, top-2, event);
L->top = top; L->top = top;
if (ttype(im) == LUA_T_NIL) { if (ttype(im) == TAG_NIL) {
im = luaT_getimbyObj(L, top-1, event); /* try second operand */ im = luaT_getimbyObj(L, top-1, event); /* try second operand */
if (ttype(im) == LUA_T_NIL) { if (ttype(im) == TAG_NIL) {
im = luaT_getim(L, 0, event); /* try a `global' method */ im = luaT_getim(L, 0, event); /* try a `global' method */
if (ttype(im) == LUA_T_NIL) if (ttype(im) == TAG_NIL)
lua_error(L, msg); lua_error(L, msg);
} }
} }
@@ -221,7 +221,7 @@ static void call_arith (lua_State *L, StkId top, IMS event) {
} }
static int luaV_strcomp (const TaggedString *ls, const TaggedString *rs) { static int luaV_strcomp (const TString *ls, const TString *rs) {
const char *l = ls->str; const char *l = ls->str;
long ll = ls->u.s.len; long ll = ls->u.s.len;
const char *r = rs->str; const char *r = rs->str;
@@ -243,9 +243,9 @@ static int luaV_strcomp (const TaggedString *ls, const TaggedString *rs) {
int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top) { int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top) {
if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) if (ttype(l) == TAG_NUMBER && ttype(r) == TAG_NUMBER)
return (nvalue(l) < nvalue(r)); return (nvalue(l) < nvalue(r));
else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) else if (ttype(l) == TAG_STRING && ttype(r) == TAG_STRING)
return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0); return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0);
else { /* call TM */ else { /* call TM */
luaD_checkstack(L, 2); luaD_checkstack(L, 2);
@@ -253,14 +253,14 @@ int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top)
*top++ = *r; *top++ = *r;
call_binTM(L, top, IM_LT, "unexpected type in comparison"); call_binTM(L, top, IM_LT, "unexpected type in comparison");
L->top--; L->top--;
return (ttype(L->top) != LUA_T_NIL); return (ttype(L->top) != TAG_NIL);
} }
} }
#define setbool(o,cond) if (cond) { \ #define setbool(o,cond) if (cond) { \
ttype(o) = LUA_T_NUMBER; nvalue(o) = 1.0; } \ ttype(o) = TAG_NUMBER; nvalue(o) = 1.0; } \
else ttype(o) = LUA_T_NIL else ttype(o) = TAG_NIL
static void strconc (lua_State *L, int total, StkId top) { static void strconc (lua_State *L, int total, StkId top) {
@@ -295,7 +295,7 @@ void luaV_pack (lua_State *L, StkId firstelem, int nvararg, TObject *tab) {
int i; int i;
Hash *htab; Hash *htab;
htab = avalue(tab) = luaH_new(L, nvararg+1); /* +1 for field `n' */ htab = avalue(tab) = luaH_new(L, nvararg+1); /* +1 for field `n' */
ttype(tab) = LUA_T_ARRAY; ttype(tab) = TAG_ARRAY;
for (i=0; i<nvararg; i++) for (i=0; i<nvararg; i++)
luaH_setint(L, htab, i+1, firstelem+i); luaH_setint(L, htab, i+1, firstelem+i);
luaV_setn(L, htab, nvararg); /* store counter in field `n' */ luaV_setn(L, htab, nvararg); /* store counter in field `n' */
@@ -321,11 +321,11 @@ static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
** Executes the given Lua function. Parameters are between [base,top). ** Executes the given Lua function. Parameters are between [base,top).
** Returns n such that the the results are between [n,top). ** Returns n such that the the results are between [n,top).
*/ */
StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, StkId luaV_execute (lua_State *L, const Closure *cl, const Proto *tf,
register StkId base) { register StkId base) {
register StkId top; /* keep top local, for performance */ register StkId top; /* keep top local, for performance */
register const Instruction *pc = tf->code; register const Instruction *pc = tf->code;
TaggedString **kstr = tf->kstr; TString **kstr = tf->kstr;
if (L->callhook) if (L->callhook)
luaD_callHook(L, base-1, L->callhook, "call"); luaD_callHook(L, base-1, L->callhook, "call");
luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK); luaD_checkstack(L, tf->maxstacksize+EXTRA_STACK);
@@ -340,124 +340,124 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
register Instruction i = *pc++; register Instruction i = *pc++;
switch (GET_OPCODE(i)) { switch (GET_OPCODE(i)) {
case ENDCODE: case OP_END:
return L->top; /* no results */ return L->top; /* no results */
case RETCODE: case OP_RETURN:
L->top = top; L->top = top;
return base+GETARG_U(i); return base+GETARG_U(i);
case CALL: case OP_CALL:
L->top = top; L->top = top;
luaD_call(L, base+GETARG_A(i), GETARG_B(i)); luaD_call(L, base+GETARG_A(i), GETARG_B(i));
top = L->top; top = L->top;
break; break;
case TAILCALL: case OP_TAILCALL:
L->top = top; L->top = top;
luaD_call(L, base+GETARG_A(i), MULT_RET); luaD_call(L, base+GETARG_A(i), MULT_RET);
return base+GETARG_B(i); return base+GETARG_B(i);
case PUSHNIL: { case OP_PUSHNIL: {
int n = GETARG_U(i); int n = GETARG_U(i);
LUA_ASSERT(L, n>0, "invalid argument"); LUA_ASSERT(L, n>0, "invalid argument");
do { do {
ttype(top++) = LUA_T_NIL; ttype(top++) = TAG_NIL;
} while (--n > 0); } while (--n > 0);
break; break;
} }
case POP: case OP_POP:
top -= GETARG_U(i); top -= GETARG_U(i);
break; break;
case PUSHINT: case OP_PUSHINT:
ttype(top) = LUA_T_NUMBER; ttype(top) = TAG_NUMBER;
nvalue(top) = (real)GETARG_S(i); nvalue(top) = (Number)GETARG_S(i);
top++; top++;
break; break;
case PUSHSTRING: case OP_PUSHSTRING:
ttype(top) = LUA_T_STRING; ttype(top) = TAG_STRING;
tsvalue(top) = kstr[GETARG_U(i)]; tsvalue(top) = kstr[GETARG_U(i)];
top++; top++;
break; break;
case PUSHNUM: case OP_PUSHNUM:
ttype(top) = LUA_T_NUMBER; ttype(top) = TAG_NUMBER;
nvalue(top) = tf->knum[GETARG_U(i)]; nvalue(top) = tf->knum[GETARG_U(i)];
top++; top++;
break; break;
case PUSHNEGNUM: case OP_PUSHNEGNUM:
ttype(top) = LUA_T_NUMBER; ttype(top) = TAG_NUMBER;
nvalue(top) = -tf->knum[GETARG_U(i)]; nvalue(top) = -tf->knum[GETARG_U(i)];
top++; top++;
break; break;
case PUSHUPVALUE: case OP_PUSHUPVALUE:
*top++ = cl->consts[GETARG_U(i)+1]; *top++ = cl->consts[GETARG_U(i)+1];
break; break;
case PUSHLOCAL: case OP_PUSHLOCAL:
*top++ = *(base+GETARG_U(i)); *top++ = *(base+GETARG_U(i));
break; break;
case GETGLOBAL: case OP_GETGLOBAL:
luaV_getglobal(L, kstr[GETARG_U(i)]->u.s.gv, top); luaV_getglobal(L, kstr[GETARG_U(i)]->u.s.gv, top);
top++; top++;
break; break;
case GETTABLE: case OP_GETTABLE:
luaV_gettable(L, top); luaV_gettable(L, top);
top--; top--;
break; break;
case GETDOTTED: case OP_GETDOTTED:
ttype(top) = LUA_T_STRING; ttype(top) = TAG_STRING;
tsvalue(top++) = kstr[GETARG_U(i)]; tsvalue(top++) = kstr[GETARG_U(i)];
luaV_gettable(L, top); luaV_gettable(L, top);
top--; top--;
break; break;
case PUSHSELF: { case OP_PUSHSELF: {
TObject receiver; TObject receiver;
receiver = *(top-1); receiver = *(top-1);
ttype(top) = LUA_T_STRING; ttype(top) = TAG_STRING;
tsvalue(top++) = kstr[GETARG_U(i)]; tsvalue(top++) = kstr[GETARG_U(i)];
luaV_gettable(L, top); luaV_gettable(L, top);
*(top-1) = receiver; *(top-1) = receiver;
break; break;
} }
case CREATETABLE: case OP_CREATETABLE:
L->top = top; L->top = top;
luaC_checkGC(L); luaC_checkGC(L);
avalue(top) = luaH_new(L, GETARG_U(i)); avalue(top) = luaH_new(L, GETARG_U(i));
ttype(top) = LUA_T_ARRAY; ttype(top) = TAG_ARRAY;
top++; top++;
break; break;
case SETLOCAL: case OP_SETLOCAL:
*(base+GETARG_U(i)) = *(--top); *(base+GETARG_U(i)) = *(--top);
break; break;
case SETGLOBAL: case OP_SETGLOBAL:
luaV_setglobal(L, kstr[GETARG_U(i)]->u.s.gv, top); luaV_setglobal(L, kstr[GETARG_U(i)]->u.s.gv, top);
top--; top--;
break; break;
case SETTABLEPOP: case OP_SETTABLEPOP:
luaV_settable(L, top-3, top); luaV_settable(L, top-3, top);
top -= 3; /* pop table, index, and value */ top -= 3; /* pop table, index, and value */
break; break;
case SETTABLE: case OP_SETTABLE:
luaV_settable(L, top-3-GETARG_U(i), top); luaV_settable(L, top-3-GETARG_U(i), top);
top--; /* pop value */ top--; /* pop value */
break; break;
case SETLIST: { case OP_SETLIST: {
int aux = GETARG_A(i) * LFIELDS_PER_FLUSH; int aux = GETARG_A(i) * LFIELDS_PER_FLUSH;
int n = GETARG_B(i)+1; int n = GETARG_B(i)+1;
Hash *arr = avalue(top-n-1); Hash *arr = avalue(top-n-1);
@@ -467,7 +467,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
break; break;
} }
case SETMAP: { case OP_SETMAP: {
int n = GETARG_U(i); int n = GETARG_U(i);
StkId finaltop = top-2*(n+1); StkId finaltop = top-2*(n+1);
Hash *arr = avalue(finaltop-1); Hash *arr = avalue(finaltop-1);
@@ -479,7 +479,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
break; break;
} }
case ADDOP: case OP_ADD:
if (tonumber(top-1) || tonumber(top-2)) if (tonumber(top-1) || tonumber(top-2))
call_arith(L, top, IM_ADD); call_arith(L, top, IM_ADD);
else else
@@ -487,17 +487,17 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
top--; top--;
break; break;
case ADDI: case OP_ADDI:
if (tonumber(top-1)) { if (tonumber(top-1)) {
ttype(top) = LUA_T_NUMBER; ttype(top) = TAG_NUMBER;
nvalue(top) = (real)GETARG_S(i); nvalue(top) = (Number)GETARG_S(i);
call_arith(L, top+1, IM_ADD); call_arith(L, top+1, IM_ADD);
} }
else else
nvalue(top-1) += (real)GETARG_S(i); nvalue(top-1) += (Number)GETARG_S(i);
break; break;
case SUBOP: case OP_SUB:
if (tonumber(top-1) || tonumber(top-2)) if (tonumber(top-1) || tonumber(top-2))
call_arith(L, top, IM_SUB); call_arith(L, top, IM_SUB);
else else
@@ -505,7 +505,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
top--; top--;
break; break;
case MULTOP: case OP_MULT:
if (tonumber(top-1) || tonumber(top-2)) if (tonumber(top-1) || tonumber(top-2))
call_arith(L, top, IM_MUL); call_arith(L, top, IM_MUL);
else else
@@ -513,7 +513,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
top--; top--;
break; break;
case DIVOP: case OP_DIV:
if (tonumber(top-1) || tonumber(top-2)) if (tonumber(top-1) || tonumber(top-2))
call_arith(L, top, IM_DIV); call_arith(L, top, IM_DIV);
else else
@@ -521,12 +521,12 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
top--; top--;
break; break;
case POWOP: case OP_POW:
call_binTM(L, top, IM_POW, "undefined operation"); call_binTM(L, top, IM_POW, "undefined operation");
top--; top--;
break; break;
case CONCOP: { case OP_CONC: {
int n = GETARG_U(i); int n = GETARG_U(i);
strconc(L, n, top); strconc(L, n, top);
top -= n-1; top -= n-1;
@@ -535,80 +535,80 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
break; break;
} }
case MINUSOP: case OP_MINUS:
if (tonumber(top-1)) { if (tonumber(top-1)) {
ttype(top) = LUA_T_NIL; ttype(top) = TAG_NIL;
call_arith(L, top+1, IM_UNM); call_arith(L, top+1, IM_UNM);
} }
else else
nvalue(top-1) = -nvalue(top-1); nvalue(top-1) = -nvalue(top-1);
break; break;
case NOTOP: case OP_NOT:
ttype(top-1) = ttype(top-1) =
(ttype(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; (ttype(top-1) == TAG_NIL) ? TAG_NUMBER : TAG_NIL;
nvalue(top-1) = 1; nvalue(top-1) = 1;
break; break;
case IFNEQJMP: case OP_IFNEQJMP:
top -= 2; top -= 2;
if (!luaO_equalObj(top, top+1)) pc += GETARG_S(i); if (!luaO_equalObj(top, top+1)) pc += GETARG_S(i);
break; break;
case IFEQJMP: case OP_IFEQJMP:
top -= 2; top -= 2;
if (luaO_equalObj(top, top+1)) pc += GETARG_S(i); if (luaO_equalObj(top, top+1)) pc += GETARG_S(i);
break; break;
case IFLTJMP: case OP_IFLTJMP:
top -= 2; top -= 2;
if (luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i); if (luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i);
break; break;
case IFLEJMP: /* a <= b === !(b<a) */ case OP_IFLEJMP: /* a <= b === !(b<a) */
top -= 2; top -= 2;
if (!luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i); if (!luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i);
break; break;
case IFGTJMP: /* a > b === (b<a) */ case OP_IFGTJMP: /* a > b === (b<a) */
top -= 2; top -= 2;
if (luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i); if (luaV_lessthan(L, top+1, top, top+2)) pc += GETARG_S(i);
break; break;
case IFGEJMP: /* a >= b === !(a<b) */ case OP_IFGEJMP: /* a >= b === !(a<b) */
top -= 2; top -= 2;
if (!luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i); if (!luaV_lessthan(L, top, top+1, top+2)) pc += GETARG_S(i);
break; break;
case IFTJMP: case OP_IFTJMP:
if (ttype(--top) != LUA_T_NIL) pc += GETARG_S(i); if (ttype(--top) != TAG_NIL) pc += GETARG_S(i);
break; break;
case IFFJMP: case OP_IFFJMP:
if (ttype(--top) == LUA_T_NIL) pc += GETARG_S(i); if (ttype(--top) == TAG_NIL) pc += GETARG_S(i);
break; break;
case ONTJMP: case OP_ONTJMP:
if (ttype(top-1) != LUA_T_NIL) pc += GETARG_S(i); if (ttype(top-1) != TAG_NIL) pc += GETARG_S(i);
else top--; else top--;
break; break;
case ONFJMP: case OP_ONFJMP:
if (ttype(top-1) == LUA_T_NIL) pc += GETARG_S(i); if (ttype(top-1) == TAG_NIL) pc += GETARG_S(i);
else top--; else top--;
break; break;
case JMP: case OP_JMP:
pc += GETARG_S(i); pc += GETARG_S(i);
break; break;
case PUSHNILJMP: case OP_PUSHNILJMP:
ttype(top++) = LUA_T_NIL; ttype(top++) = TAG_NIL;
pc++; pc++;
break; break;
case CLOSURE: case OP_CLOSURE:
ttype(top) = LUA_T_LPROTO; ttype(top) = TAG_LPROTO;
tfvalue(top) = tf->kproto[GETARG_A(i)]; tfvalue(top) = tf->kproto[GETARG_A(i)];
L->top = ++top; L->top = ++top;
luaV_closure(L, GETARG_B(i)); luaV_closure(L, GETARG_B(i));
@@ -616,14 +616,14 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
luaC_checkGC(L); luaC_checkGC(L);
break; break;
case SETLINE: case OP_SETLINE:
if ((base-1)->ttype != LUA_T_LINE) { if ((base-1)->ttype != TAG_LINE) {
/* open space for LINE value */ /* open space for LINE value */
int n = top-base; int n = top-base;
while (n--) base[n+1] = base[n]; while (n--) base[n+1] = base[n];
base++; base++;
top++; top++;
(base-1)->ttype = LUA_T_LINE; (base-1)->ttype = TAG_LINE;
} }
(base-1)->value.i = GETARG_U(i); (base-1)->value.i = GETARG_U(i);
if (L->linehook) { if (L->linehook) {

8
lvm.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lvm.h,v 1.17 2000/03/03 14:58:26 roberto Exp $ ** $Id: lvm.h,v 1.18 2000/03/09 00:19:22 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -13,8 +13,8 @@
#include "ltm.h" #include "ltm.h"
#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (luaV_tonumber(o) != 0)) #define tonumber(o) ((ttype(o) != TAG_NUMBER) && (luaV_tonumber(o) != 0))
#define tostring(L,o) ((ttype(o) != LUA_T_STRING) && (luaV_tostring(L, o) != 0)) #define tostring(L,o) ((ttype(o) != TAG_STRING) && (luaV_tostring(L, o) != 0))
void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab); void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab);
@@ -26,7 +26,7 @@ void luaV_settable (lua_State *L, StkId t, StkId top);
void luaV_rawsettable (lua_State *L, StkId t); void luaV_rawsettable (lua_State *L, StkId t);
void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top); void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top);
void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top); void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top);
StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, StkId base); StkId luaV_execute (lua_State *L, const Closure *cl, const Proto *tf, StkId base);
void luaV_closure (lua_State *L, int nelems); void luaV_closure (lua_State *L, int nelems);
int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top); int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top);