avoid gotos when possible

This commit is contained in:
Roberto Ierusalimschy
2002-06-14 14:21:32 -03:00
parent 8fd0f6a82b
commit c31494df26

40
lvm.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 1.237 2002/06/12 14:51:31 roberto Exp roberto $
** $Id: lvm.c,v 1.238 2002/06/13 13:39:55 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -118,7 +118,7 @@ static void callTM (lua_State *L, const TObject *f,
void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
const TObject *tm;
int loop = 0;
init:
do {
if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
Table *h = hvalue(t);
Table *et = h->metatable;
@@ -131,19 +131,16 @@ void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
}
}
/* else will try the tag method */
} else { /* not a table; try a `gettable' tag method */
if (ttype(tm = luaT_gettmbyobj(L, t, TM_GETTABLE)) == LUA_TNIL) {
}
else if (ttype(tm = luaT_gettmbyobj(L, t, TM_GETTABLE)) == LUA_TNIL)
luaG_typeerror(L, t, "index");
return; /* to avoid warnings */
}
}
if (ttype(tm) == LUA_TFUNCTION)
if (ttype(tm) == LUA_TFUNCTION) {
callTMres(L, tm, t, key, res);
else {
if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in gettable");
t = tm;
goto init; /* return luaV_gettable(L, tm, key, res); */
return;
}
t = tm; /* else repeat access with `tm' */
} while (++loop <= MAXTAGLOOP);
luaG_runerror(L, "loop in gettable");
}
@@ -153,7 +150,7 @@ void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
const TObject *tm;
int loop = 0;
init:
do {
if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
Table *h = hvalue(t);
Table *et = h->metatable;
@@ -166,19 +163,16 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
}
}
/* else will try the tag method */
} else { /* `t' is not a table; try a `settable' tag method */
if (ttype(tm = luaT_gettmbyobj(L, t, TM_SETTABLE)) == LUA_TNIL) {
}
else if (ttype(tm = luaT_gettmbyobj(L, t, TM_SETTABLE)) == LUA_TNIL)
luaG_typeerror(L, t, "index");
return; /* to avoid warnings */
}
}
if (ttype(tm) == LUA_TFUNCTION)
if (ttype(tm) == LUA_TFUNCTION) {
callTM(L, tm, t, key, val);
else {
if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in settable");
t = tm;
goto init; /* luaV_settable(L, tm, key, val); */
return;
}
t = tm; /* else repeat with `tm' */
} while (++loop <= MAXTAGLOOP);
luaG_runerror(L, "loop in settable");
}