aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-09-07 14:39:10 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-09-07 14:39:10 -0300
commitabdbe883a86bbc7fbf1d1bfc50756e1b42fc45b5 (patch)
tree051a7571c8acaf5451b5c9b7d67f1796a345c565 /ldo.c
parent4d0935ec0ffed827aade5594216fae15bed7c6b5 (diff)
downloadlua-abdbe883a86bbc7fbf1d1bfc50756e1b42fc45b5.tar.gz
lua-abdbe883a86bbc7fbf1d1bfc50756e1b42fc45b5.tar.bz2
lua-abdbe883a86bbc7fbf1d1bfc50756e1b42fc45b5.zip
first implementation of unrestricted static scoping
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/ldo.c b/ldo.c
index 92953d92..36e9cf7e 100644
--- a/ldo.c
+++ b/ldo.c
@@ -15,6 +15,7 @@
15 15
16#include "ldebug.h" 16#include "ldebug.h"
17#include "ldo.h" 17#include "ldo.h"
18#include "lfunc.h"
18#include "lgc.h" 19#include "lgc.h"
19#include "lmem.h" 20#include "lmem.h"
20#include "lobject.h" 21#include "lobject.h"
@@ -122,9 +123,9 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl) {
122 int n; 123 int n;
123 luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ 124 luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */
124 for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ 125 for (n=0; n<nup; n++) /* copy upvalues as extra arguments */
125 setobj(L->top++, &cl->upvalue[n]); 126 setobj(L->top++, &cl->u.c.upvalue[n]);
126 lua_unlock(L); 127 lua_unlock(L);
127 n = (*cl->f.c)(L); /* do the actual call */ 128 n = (*cl->u.c.f)(L); /* do the actual call */
128 lua_lock(L); 129 lua_lock(L);
129 return L->top - n; /* return index of first result */ 130 return L->top - n; /* return index of first result */
130} 131}
@@ -209,7 +210,12 @@ struct SParser { /* data to `f_parser' */
209static void f_parser (lua_State *L, void *ud) { 210static void f_parser (lua_State *L, void *ud) {
210 struct SParser *p = cast(struct SParser *, ud); 211 struct SParser *p = cast(struct SParser *, ud);
211 Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); 212 Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z);
212 luaV_Lclosure(L, tf, 0); 213 Closure *cl = luaF_newLclosure(L, 0);
214 cl->u.l.p = tf;
215 luaF_LConlist(L, cl);
216 setclvalue(L->top, cl);
217 incr_top;
218
213} 219}
214 220
215 221
@@ -286,6 +292,9 @@ struct lua_longjmp {
286 jmp_buf b; 292 jmp_buf b;
287 struct lua_longjmp *previous; 293 struct lua_longjmp *previous;
288 volatile int status; /* error code */ 294 volatile int status; /* error code */
295 CallInfo *ci; /* call info of active function that set protection */
296 StkId top; /* top stack when protection was set */
297 int allowhooks; /* `allowhook' state when protection was set */
289}; 298};
290 299
291 300
@@ -325,19 +334,20 @@ void luaD_breakrun (lua_State *L, int errcode) {
325 334
326 335
327int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud) { 336int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud) {
328 CallInfo *oldci = L->ci;
329 StkId oldtop = L->top;
330 struct lua_longjmp lj; 337 struct lua_longjmp lj;
331 int allowhooks = L->allowhooks; 338 lj.ci = L->ci;
339 lj.top = L->top;
340 lj.allowhooks = L->allowhooks;
332 lj.status = 0; 341 lj.status = 0;
333 lj.previous = L->errorJmp; /* chain new error handler */ 342 lj.previous = L->errorJmp; /* chain new error handler */
334 L->errorJmp = &lj; 343 L->errorJmp = &lj;
335 if (setjmp(lj.b) == 0) 344 if (setjmp(lj.b) == 0)
336 (*f)(L, ud); 345 (*f)(L, ud);
337 else { /* an error occurred: restore the state */ 346 else { /* an error occurred: restore the state */
338 L->allowhooks = allowhooks; 347 luaF_close(L, lj.top); /* close eventual pending closures */
339 L->ci = oldci; 348 L->ci = lj.ci;
340 L->top = oldtop; 349 L->top = lj.top;
350 L->allowhooks = lj.allowhooks;
341 restore_stack_limit(L); 351 restore_stack_limit(L);
342 } 352 }
343 L->errorJmp = lj.previous; /* restore old error handler */ 353 L->errorJmp = lj.previous; /* restore old error handler */