avoid gotos when possible

This commit is contained in:
Roberto Ierusalimschy 2002-06-14 14:21:32 -03:00
parent 8fd0f6a82b
commit c31494df26
1 changed files with 39 additions and 45 deletions

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 ** Lua virtual machine
** See Copyright Notice in lua.h ** 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) { void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
const TObject *tm; const TObject *tm;
int loop = 0; int loop = 0;
init: do {
if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */ if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
Table *h = hvalue(t); Table *h = hvalue(t);
Table *et = h->metatable; 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 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"); 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); callTMres(L, tm, t, key, res);
else { return;
if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in gettable");
t = tm;
goto init; /* return luaV_gettable(L, tm, key, res); */
} }
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) { void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
const TObject *tm; const TObject *tm;
int loop = 0; int loop = 0;
init: do {
if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */ if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
Table *h = hvalue(t); Table *h = hvalue(t);
Table *et = h->metatable; 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 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"); 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); callTM(L, tm, t, key, val);
else { return;
if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in settable");
t = tm;
goto init; /* luaV_settable(L, tm, key, val); */
} }
t = tm; /* else repeat with `tm' */
} while (++loop <= MAXTAGLOOP);
luaG_runerror(L, "loop in settable");
} }