summaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-05 09:14:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-05 09:14:08 -0300
commit001f2bdd0e2f8803889c1b5164b57a51e44aef5b (patch)
treed200cf4d708be3c61e64640c45b47050c9c6a375 /ldo.c
parentcd2ddaded97f7f2b2af02cecfd165cf70e6f83f4 (diff)
downloadlua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.gz
lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.bz2
lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.zip
new definition for types-tags
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c56
1 files changed, 25 insertions, 31 deletions
diff --git a/ldo.c b/ldo.c
index f9f1d113..281ef22e 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.100 2000/10/02 20:10:55 roberto Exp roberto $ 2** $Id: ldo.c,v 1.101 2000/10/04 12:16:08 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*/
@@ -73,7 +73,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) {
73 else { 73 else {
74 luaD_checkstack(L, diff); 74 luaD_checkstack(L, diff);
75 while (diff--) 75 while (diff--)
76 ttype(L->top++) = TAG_NIL; 76 ttype(L->top++) = LUA_TNIL;
77 } 77 }
78} 78}
79 79
@@ -91,7 +91,7 @@ static void luaD_openstack (lua_State *L, StkId pos) {
91static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { 91static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) {
92 StkId old_Cbase = L->Cbase; 92 StkId old_Cbase = L->Cbase;
93 StkId old_top = L->Cbase = L->top; 93 StkId old_top = L->Cbase = L->top;
94 luaD_checkstack(L, LUA_MINSTACK); /* assures minimum stack size */ 94 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
95 L->allowhooks = 0; /* cannot call hooks inside a hook */ 95 L->allowhooks = 0; /* cannot call hooks inside a hook */
96 (*hook)(L, ar); 96 (*hook)(L, ar);
97 LUA_ASSERT(L->allowhooks == 0, "invalid allow"); 97 LUA_ASSERT(L->allowhooks == 0, "invalid allow");
@@ -129,7 +129,7 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) {
129 StkId old_Cbase = L->Cbase; 129 StkId old_Cbase = L->Cbase;
130 int n; 130 int n;
131 L->Cbase = base; /* new base for C function */ 131 L->Cbase = base; /* new base for C function */
132 luaD_checkstack(L, nup+LUA_MINSTACK); /* assures minimum stack size */ 132 luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */
133 for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ 133 for (n=0; n<nup; n++) /* copy upvalues as extra arguments */
134 *(L->top++) = cl->upvalue[n]; 134 *(L->top++) = cl->upvalue[n];
135 if (callhook) 135 if (callhook)
@@ -159,32 +159,26 @@ void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) {
159*/ 159*/
160void luaD_call (lua_State *L, StkId func, int nResults) { 160void luaD_call (lua_State *L, StkId func, int nResults) {
161 StkId firstResult; 161 StkId firstResult;
162 retry: /* for `function' tag method */ 162 CallInfo ci;
163 switch (ttype(func)) { 163 Closure *cl;
164 case TAG_LCLOSURE: { 164 if (ttype(func) != LUA_TFUNCTION) {
165 CallInfo ci; 165 /* `func' is not a function; check the `function' tag method */
166 ci.func = clvalue(func); 166 const TObject *im = luaT_getimbyObj(L, func, IM_FUNCTION);
167 infovalue(func) = &ci; 167 if (ttype(im) == LUA_TNIL)
168 ttype(func) = TAG_LMARK; 168 luaG_typeerror(L, func, "call");
169 firstResult = luaV_execute(L, ci.func, func+1); 169 luaD_openstack(L, func);
170 LUA_ASSERT(ttype(func) == TAG_LMARK, "invalid tag"); 170 *func = *im; /* tag method is the new function to be called */
171 break; 171 LUA_ASSERT(ttype(func) == LUA_TFUNCTION, "invalid tag method");
172 }
173 case TAG_CCLOSURE: {
174 ttype(func) = TAG_CMARK;
175 firstResult = callCclosure(L, clvalue(func), func+1);
176 LUA_ASSERT(ttype(func) == TAG_CMARK, "invalid tag");
177 break;
178 }
179 default: { /* `func' is not a function; check the `function' tag method */
180 const TObject *im = luaT_getimbyObj(L, func, IM_FUNCTION);
181 if (ttype(im) == TAG_NIL)
182 luaG_typeerror(L, func, "call");
183 luaD_openstack(L, func);
184 *func = *im; /* tag method is the new function to be called */
185 goto retry; /* retry the call */
186 }
187 } 172 }
173 cl = clvalue(func);
174 ci.func = cl;
175 infovalue(func) = &ci;
176 ttype(func) = LUA_TMARK;
177 if (cl->isC)
178 firstResult = callCclosure(L, cl, func+1);
179 else
180 firstResult = luaV_execute(L, cl, func+1);
181 LUA_ASSERT(ttype(func) == LUA_TMARK, "invalid tag");
188 /* adjust the number of results */ 182 /* adjust the number of results */
189 if (nResults == LUA_MULTRET) 183 if (nResults == LUA_MULTRET)
190 nResults = L->top - firstResult; 184 nResults = L->top - firstResult;
@@ -250,7 +244,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
250 old_blocks = L->nblocks; 244 old_blocks = L->nblocks;
251 status = luaD_runprotected(L, f_parser, &p); 245 status = luaD_runprotected(L, f_parser, &p);
252 if (status == 0) { 246 if (status == 0) {
253 /* add new memory to threshould (as it probably will stay) */ 247 /* add new memory to threshold (as it probably will stay) */
254 L->GCthreshold += (L->nblocks - old_blocks); 248 L->GCthreshold += (L->nblocks - old_blocks);
255 } 249 }
256 else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ 250 else if (status == LUA_ERRRUN) /* an error occurred: correct error code */
@@ -331,7 +325,7 @@ struct lua_longjmp {
331 325
332static void message (lua_State *L, const char *s) { 326static void message (lua_State *L, const char *s) {
333 const TObject *em = luaH_getglobal(L, LUA_ERRORMESSAGE); 327 const TObject *em = luaH_getglobal(L, LUA_ERRORMESSAGE);
334 if (luaO_type(em) == LUA_TFUNCTION) { 328 if (ttype(em) == LUA_TFUNCTION) {
335 *L->top = *em; 329 *L->top = *em;
336 incr_top; 330 incr_top;
337 lua_pushstring(L, s); 331 lua_pushstring(L, s);