diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-18 13:59:09 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-18 13:59:09 -0200 |
commit | f2c451d7455aad3496f32dfa2bfca7f7e8b5376d (patch) | |
tree | 38e30f839516ff5b6178351750b5e3256f4dd98e /ldo.c | |
parent | 619edfd9e4c210bdfcfbf1e911d1760c53c4293f (diff) | |
download | lua-f2c451d7455aad3496f32dfa2bfca7f7e8b5376d.tar.gz lua-f2c451d7455aad3496f32dfa2bfca7f7e8b5376d.tar.bz2 lua-f2c451d7455aad3496f32dfa2bfca7f7e8b5376d.zip |
all accesses to TObjects done through macros
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.112 2001/01/10 16:58:11 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.113 2001/01/10 18:56:11 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -74,7 +74,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) { | |||
74 | else { | 74 | else { |
75 | luaD_checkstack(L, diff); | 75 | luaD_checkstack(L, diff); |
76 | while (diff--) | 76 | while (diff--) |
77 | ttype(L->top++) = LUA_TNIL; | 77 | setnilvalue(L->top++); |
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
@@ -84,7 +84,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) { | |||
84 | */ | 84 | */ |
85 | static void luaD_openstack (lua_State *L, StkId pos) { | 85 | static void luaD_openstack (lua_State *L, StkId pos) { |
86 | int i = L->top-pos; | 86 | int i = L->top-pos; |
87 | while (i--) pos[i+1] = pos[i]; | 87 | while (i--) setobj(pos+i+1, pos+i); |
88 | incr_top; | 88 | incr_top; |
89 | } | 89 | } |
90 | 90 | ||
@@ -132,7 +132,7 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { | |||
132 | L->Cbase = base; /* new base for C function */ | 132 | L->Cbase = base; /* new base for C function */ |
133 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ | 133 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ |
134 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ | 134 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ |
135 | *(L->top++) = cl->upvalue[n]; | 135 | setobj(L->top++, &cl->upvalue[n]); |
136 | n = (*cl->f.c)(L); /* do the actual call */ | 136 | n = (*cl->f.c)(L); /* do the actual call */ |
137 | L->Cbase = old_Cbase; /* restore old C base */ | 137 | L->Cbase = old_Cbase; /* restore old C base */ |
138 | return L->top - n; /* return index of first result */ | 138 | return L->top - n; /* return index of first result */ |
@@ -142,8 +142,7 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { | |||
142 | void luaD_callTM (lua_State *L, Closure *f, int nParams, int nResults) { | 142 | void luaD_callTM (lua_State *L, Closure *f, int nParams, int nResults) { |
143 | StkId base = L->top - nParams; | 143 | StkId base = L->top - nParams; |
144 | luaD_openstack(L, base); | 144 | luaD_openstack(L, base); |
145 | clvalue(base) = f; | 145 | setclvalue(base, f); |
146 | ttype(base) = LUA_TFUNCTION; | ||
147 | luaD_call(L, base, nResults); | 146 | luaD_call(L, base, nResults); |
148 | } | 147 | } |
149 | 148 | ||
@@ -166,13 +165,11 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
166 | if (tm == NULL) | 165 | if (tm == NULL) |
167 | luaG_typeerror(L, func, "call"); | 166 | luaG_typeerror(L, func, "call"); |
168 | luaD_openstack(L, func); | 167 | luaD_openstack(L, func); |
169 | clvalue(func) = tm; /* tag method is the new function to be called */ | 168 | setclvalue(func, tm); /* tag method is the new function to be called */ |
170 | ttype(func) = LUA_TFUNCTION; | ||
171 | } | 169 | } |
172 | cl = clvalue(func); | 170 | cl = clvalue(func); |
173 | ci.func = cl; | 171 | ci.func = cl; |
174 | infovalue(func) = &ci; | 172 | setivalue(func, &ci); |
175 | ttype(func) = LUA_TMARK; | ||
176 | callhook = L->callhook; | 173 | callhook = L->callhook; |
177 | if (callhook) | 174 | if (callhook) |
178 | luaD_callHook(L, func, callhook, "call"); | 175 | luaD_callHook(L, func, callhook, "call"); |
@@ -184,15 +181,15 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
184 | /* move results to `func' (to erase parameters and function) */ | 181 | /* move results to `func' (to erase parameters and function) */ |
185 | if (nResults == LUA_MULTRET) { | 182 | if (nResults == LUA_MULTRET) { |
186 | while (firstResult < L->top) /* copy all results */ | 183 | while (firstResult < L->top) /* copy all results */ |
187 | *func++ = *firstResult++; | 184 | setobj(func++, firstResult++); |
188 | L->top = func; | 185 | L->top = func; |
189 | } | 186 | } |
190 | else { /* copy at most `nResults' */ | 187 | else { /* copy at most `nResults' */ |
191 | for (; nResults > 0 && firstResult < L->top; nResults--) | 188 | for (; nResults > 0 && firstResult < L->top; nResults--) |
192 | *func++ = *firstResult++; | 189 | setobj(func++, firstResult++); |
193 | L->top = func; | 190 | L->top = func; |
194 | for (; nResults > 0; nResults--) { /* if there are not enough results */ | 191 | for (; nResults > 0; nResults--) { /* if there are not enough results */ |
195 | ttype(L->top) = LUA_TNIL; /* adjust the stack */ | 192 | setnilvalue(L->top); /* adjust the stack */ |
196 | incr_top; /* must check stack space */ | 193 | incr_top; /* must check stack space */ |
197 | } | 194 | } |
198 | } | 195 | } |
@@ -334,7 +331,7 @@ struct lua_longjmp { | |||
334 | static void message (lua_State *L, const char *s) { | 331 | static void message (lua_State *L, const char *s) { |
335 | const TObject *em = luaH_getstr(L->gt, luaS_newliteral(L, LUA_ERRORMESSAGE)); | 332 | const TObject *em = luaH_getstr(L->gt, luaS_newliteral(L, LUA_ERRORMESSAGE)); |
336 | if (ttype(em) == LUA_TFUNCTION) { | 333 | if (ttype(em) == LUA_TFUNCTION) { |
337 | *L->top = *em; | 334 | setobj(L->top, em); |
338 | incr_top; | 335 | incr_top; |
339 | lua_pushstring(L, s); | 336 | lua_pushstring(L, s); |
340 | luaD_call(L, L->top-2, 0); | 337 | luaD_call(L, L->top-2, 0); |