aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/ldo.c b/ldo.c
index 911c544f..ec7897f9 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.114 2001/01/18 15:59:09 roberto Exp roberto $ 2** $Id: ldo.c,v 1.115 2001/01/19 13:20:30 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*/
@@ -56,7 +56,7 @@ void luaD_checkstack (lua_State *L, int n) {
56 else { 56 else {
57 L->stack_last += EXTRA_STACK; /* to be used by error message */ 57 L->stack_last += EXTRA_STACK; /* to be used by error message */
58 lua_assert(L->stack_last == L->stack+L->stacksize-1); 58 lua_assert(L->stack_last == L->stack+L->stacksize-1);
59 lua_error(L, "stack overflow"); 59 luaD_error(L, "stack overflow");
60 } 60 }
61 } 61 }
62} 62}
@@ -94,7 +94,9 @@ static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) {
94 StkId old_top = L->Cbase = L->top; 94 StkId old_top = L->Cbase = L->top;
95 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ 95 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
96 L->allowhooks = 0; /* cannot call hooks inside a hook */ 96 L->allowhooks = 0; /* cannot call hooks inside a hook */
97 LUA_EXIT;
97 (*hook)(L, ar); 98 (*hook)(L, ar);
99 LUA_ENTRY;
98 lua_assert(L->allowhooks == 0); 100 lua_assert(L->allowhooks == 0);
99 L->allowhooks = 1; 101 L->allowhooks = 1;
100 L->top = old_top; 102 L->top = old_top;
@@ -133,7 +135,9 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) {
133 luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ 135 luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */
134 for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ 136 for (n=0; n<nup; n++) /* copy upvalues as extra arguments */
135 setobj(L->top++, &cl->upvalue[n]); 137 setobj(L->top++, &cl->upvalue[n]);
138 LUA_EXIT;
136 n = (*cl->f.c)(L); /* do the actual call */ 139 n = (*cl->f.c)(L); /* do the actual call */
140 LUA_ENTRY;
137 L->Cbase = old_Cbase; /* restore old C base */ 141 L->Cbase = old_Cbase; /* restore old C base */
138 return L->top - n; /* return index of first result */ 142 return L->top - n; /* return index of first result */
139} 143}
@@ -212,13 +216,16 @@ static void f_call (lua_State *L, void *ud) {
212 216
213 217
214LUA_API int lua_call (lua_State *L, int nargs, int nresults) { 218LUA_API int lua_call (lua_State *L, int nargs, int nresults) {
215 StkId func = L->top - (nargs+1); /* function to be called */ 219 StkId func;
216 struct CallS c; 220 struct CallS c;
217 int status; 221 int status;
222 LUA_ENTRY;
223 func = L->top - (nargs+1); /* function to be called */
218 c.func = func; c.nresults = nresults; 224 c.func = func; c.nresults = nresults;
219 status = luaD_runprotected(L, f_call, &c); 225 status = luaD_runprotected(L, f_call, &c);
220 if (status != 0) /* an error occurred? */ 226 if (status != 0) /* an error occurred? */
221 L->top = func; /* remove parameters from the stack */ 227 L->top = func; /* remove parameters from the stack */
228 LUA_EXIT;
222 return status; 229 return status;
223} 230}
224 231
@@ -242,6 +249,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
242 struct ParserS p; 249 struct ParserS p;
243 mem_int old_blocks; 250 mem_int old_blocks;
244 int status; 251 int status;
252 LUA_ENTRY;
245 p.z = z; p.bin = bin; 253 p.z = z; p.bin = bin;
246 luaC_checkGC(L); 254 luaC_checkGC(L);
247 old_blocks = G(L)->nblocks; 255 old_blocks = G(L)->nblocks;
@@ -253,6 +261,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
253 } 261 }
254 else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ 262 else if (status == LUA_ERRRUN) /* an error occurred: correct error code */
255 status = LUA_ERRSYNTAX; 263 status = LUA_ERRSYNTAX;
264 LUA_EXIT;
256 return status; 265 return status;
257} 266}
258 267
@@ -275,9 +284,9 @@ static int parse_file (lua_State *L, const char *filename) {
275 lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename); 284 lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename);
276 lua_concat(L, 2); 285 lua_concat(L, 2);
277 filename = lua_tostring(L, -1); /* filename = '@'..filename */ 286 filename = lua_tostring(L, -1); /* filename = '@'..filename */
278 lua_pop(L, 1); /* OK: there is no GC during parser */
279 luaZ_Fopen(&z, f, filename); 287 luaZ_Fopen(&z, f, filename);
280 status = protectedparser(L, &z, bin); 288 status = protectedparser(L, &z, bin);
289 lua_remove(L, -2); /* remove filename */
281 if (f != stdin) 290 if (f != stdin)
282 fclose(f); 291 fclose(f);
283 return status; 292 return status;
@@ -285,7 +294,8 @@ static int parse_file (lua_State *L, const char *filename) {
285 294
286 295
287LUA_API int lua_dofile (lua_State *L, const char *filename) { 296LUA_API int lua_dofile (lua_State *L, const char *filename) {
288 int status = parse_file(L, filename); 297 int status;
298 status = parse_file(L, filename);
289 if (status == 0) /* parse OK? */ 299 if (status == 0) /* parse OK? */
290 status = lua_call(L, 0, LUA_MULTRET); /* call main */ 300 status = lua_call(L, 0, LUA_MULTRET); /* call main */
291 return status; 301 return status;
@@ -295,14 +305,17 @@ LUA_API int lua_dofile (lua_State *L, const char *filename) {
295static int parse_buffer (lua_State *L, const char *buff, size_t size, 305static int parse_buffer (lua_State *L, const char *buff, size_t size,
296 const char *name) { 306 const char *name) {
297 ZIO z; 307 ZIO z;
308 int status;
298 if (!name) name = "?"; 309 if (!name) name = "?";
299 luaZ_mopen(&z, buff, size, name); 310 luaZ_mopen(&z, buff, size, name);
300 return protectedparser(L, &z, buff[0]==ID_CHUNK); 311 status = protectedparser(L, &z, buff[0]==ID_CHUNK);
312 return status;
301} 313}
302 314
303 315
304LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name) { 316LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name) {
305 int status = parse_buffer(L, buff, size, name); 317 int status;
318 status = parse_buffer(L, buff, size, name);
306 if (status == 0) /* parse OK? */ 319 if (status == 0) /* parse OK? */
307 status = lua_call(L, 0, LUA_MULTRET); /* call main */ 320 status = lua_call(L, 0, LUA_MULTRET); /* call main */
308 return status; 321 return status;
@@ -333,7 +346,8 @@ static void message (lua_State *L, const char *s) {
333 if (ttype(em) == LUA_TFUNCTION) { 346 if (ttype(em) == LUA_TFUNCTION) {
334 setobj(L->top, em); 347 setobj(L->top, em);
335 incr_top; 348 incr_top;
336 lua_pushstring(L, s); 349 setsvalue(L->top, luaS_new(L, s));
350 incr_top;
337 luaD_call(L, L->top-2, 0); 351 luaD_call(L, L->top-2, 0);
338 } 352 }
339} 353}
@@ -342,7 +356,7 @@ static void message (lua_State *L, const char *s) {
342/* 356/*
343** Reports an error, and jumps up to the available recovery label 357** Reports an error, and jumps up to the available recovery label
344*/ 358*/
345LUA_API void lua_error (lua_State *L, const char *s) { 359void luaD_error (lua_State *L, const char *s) {
346 if (s) message(L, s); 360 if (s) message(L, s);
347 luaD_breakrun(L, LUA_ERRRUN); 361 luaD_breakrun(L, LUA_ERRRUN);
348} 362}