summaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-06-14 14:21:32 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-06-14 14:21:32 -0300
commitc31494df26db17fe65741cb2f994be1d43c4bfd3 (patch)
treec2de29160d6dd3bb6a7c53d9e6aed67fa09e5f10 /lvm.c
parent8fd0f6a82b63f4a2f77578fb70c9fe46047f295b (diff)
downloadlua-c31494df26db17fe65741cb2f994be1d43c4bfd3.tar.gz
lua-c31494df26db17fe65741cb2f994be1d43c4bfd3.tar.bz2
lua-c31494df26db17fe65741cb2f994be1d43c4bfd3.zip
avoid gotos when possible
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c84
1 files changed, 39 insertions, 45 deletions
diff --git a/lvm.c b/lvm.c
index 758018b3..501c22be 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.237 2002/06/12 14:51:31 roberto Exp roberto $ 2** $Id: lvm.c,v 1.238 2002/06/13 13:39:55 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -118,32 +118,29 @@ static void callTM (lua_State *L, const TObject *f,
118void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) { 118void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
119 const TObject *tm; 119 const TObject *tm;
120 int loop = 0; 120 int loop = 0;
121 init: 121 do {
122 if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */ 122 if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
123 Table *h = hvalue(t); 123 Table *h = hvalue(t);
124 Table *et = h->metatable; 124 Table *et = h->metatable;
125 if ((tm = fasttm(L, et, TM_GETTABLE)) == NULL) { /* no gettable TM? */ 125 if ((tm = fasttm(L, et, TM_GETTABLE)) == NULL) { /* no gettable TM? */
126 const TObject *v = luaH_get(h, key); /* do a primitive get */ 126 const TObject *v = luaH_get(h, key); /* do a primitive get */
127 if (ttype(v) != LUA_TNIL || /* result is no nil ... */ 127 if (ttype(v) != LUA_TNIL || /* result is no nil ... */
128 (tm = fasttm(L, et, TM_INDEX)) == NULL) { /* ... or no index TM? */ 128 (tm = fasttm(L, et, TM_INDEX)) == NULL) { /* ... or no index TM? */
129 setobj(res, v); /* default get */ 129 setobj(res, v); /* default get */
130 return; 130 return;
131 }
131 } 132 }
133 /* else will try the tag method */
132 } 134 }
133 /* else will try the tag method */ 135 else if (ttype(tm = luaT_gettmbyobj(L, t, TM_GETTABLE)) == LUA_TNIL)
134 } else { /* not a table; try a `gettable' tag method */
135 if (ttype(tm = luaT_gettmbyobj(L, t, TM_GETTABLE)) == LUA_TNIL) {
136 luaG_typeerror(L, t, "index"); 136 luaG_typeerror(L, t, "index");
137 return; /* to avoid warnings */ 137 if (ttype(tm) == LUA_TFUNCTION) {
138 callTMres(L, tm, t, key, res);
139 return;
138 } 140 }
139 } 141 t = tm; /* else repeat access with `tm' */
140 if (ttype(tm) == LUA_TFUNCTION) 142 } while (++loop <= MAXTAGLOOP);
141 callTMres(L, tm, t, key, res); 143 luaG_runerror(L, "loop in gettable");
142 else {
143 if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in gettable");
144 t = tm;
145 goto init; /* return luaV_gettable(L, tm, key, res); */
146 }
147} 144}
148 145
149 146
@@ -153,32 +150,29 @@ void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
153void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) { 150void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
154 const TObject *tm; 151 const TObject *tm;
155 int loop = 0; 152 int loop = 0;
156 init: 153 do {
157 if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */ 154 if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
158 Table *h = hvalue(t); 155 Table *h = hvalue(t);
159 Table *et = h->metatable; 156 Table *et = h->metatable;
160 if ((tm = fasttm(L, et, TM_SETTABLE)) == NULL) { /* no settable TM? */ 157 if ((tm = fasttm(L, et, TM_SETTABLE)) == NULL) { /* no settable TM? */
161 TObject *oldval = luaH_set(L, h, key); /* do a primitive set */ 158 TObject *oldval = luaH_set(L, h, key); /* do a primitive set */
162 if (ttype(oldval) != LUA_TNIL || /* result is no nil ... */ 159 if (ttype(oldval) != LUA_TNIL || /* result is no nil ... */
163 (tm = fasttm(L, et, TM_NEWINDEX)) == NULL) { /* ... or no TM? */ 160 (tm = fasttm(L, et, TM_NEWINDEX)) == NULL) { /* ... or no TM? */
164 setobj(oldval, val); 161 setobj(oldval, val);
165 return; 162 return;
163 }
166 } 164 }
165 /* else will try the tag method */
167 } 166 }
168 /* else will try the tag method */ 167 else if (ttype(tm = luaT_gettmbyobj(L, t, TM_SETTABLE)) == LUA_TNIL)
169 } else { /* `t' is not a table; try a `settable' tag method */
170 if (ttype(tm = luaT_gettmbyobj(L, t, TM_SETTABLE)) == LUA_TNIL) {
171 luaG_typeerror(L, t, "index"); 168 luaG_typeerror(L, t, "index");
172 return; /* to avoid warnings */ 169 if (ttype(tm) == LUA_TFUNCTION) {
170 callTM(L, tm, t, key, val);
171 return;
173 } 172 }
174 } 173 t = tm; /* else repeat with `tm' */
175 if (ttype(tm) == LUA_TFUNCTION) 174 } while (++loop <= MAXTAGLOOP);
176 callTM(L, tm, t, key, val); 175 luaG_runerror(L, "loop in settable");
177 else {
178 if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in settable");
179 t = tm;
180 goto init; /* luaV_settable(L, tm, key, val); */
181 }
182} 176}
183 177
184 178