diff options
-rw-r--r-- | ldebug.c | 4 | ||||
-rw-r--r-- | ldo.c | 19 | ||||
-rw-r--r-- | lstate.c | 4 | ||||
-rw-r--r-- | lstate.h | 15 | ||||
-rw-r--r-- | ltests.c | 4 | ||||
-rw-r--r-- | lvm.c | 21 | ||||
-rw-r--r-- | lvm.h | 4 |
7 files changed, 41 insertions, 30 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.39 2008/04/02 19:14:16 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.40 2008/07/03 14:24:11 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -88,7 +88,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | |||
88 | lua_lock(L); | 88 | lua_lock(L); |
89 | for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { | 89 | for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { |
90 | level--; | 90 | level--; |
91 | if (f_isLua(ci)) /* Lua function? */ | 91 | if (isLua(ci)) /* Lua function? */ |
92 | level -= ci->tailcalls; /* skip lost tail calls */ | 92 | level -= ci->tailcalls; /* skip lost tail calls */ |
93 | } | 93 | } |
94 | if (level == 0 && ci > L->base_ci) { /* level found? */ | 94 | if (level == 0 && ci > L->base_ci) { /* level found? */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.46 2008/01/18 22:36:50 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.47 2008/08/13 17:02:42 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 | */ |
@@ -193,9 +193,9 @@ void luaD_callhook (lua_State *L, int event, int line) { | |||
193 | ar.i_ci = cast_int(L->ci - L->base_ci); | 193 | ar.i_ci = cast_int(L->ci - L->base_ci); |
194 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 194 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
195 | L->ci->top = L->top + LUA_MINSTACK; | 195 | L->ci->top = L->top + LUA_MINSTACK; |
196 | L->ci->status |= 1; /* this level is running a hook */ | ||
197 | lua_assert(L->ci->top <= L->stack_last); | 196 | lua_assert(L->ci->top <= L->stack_last); |
198 | L->allowhook = 0; /* cannot call hooks inside a hook */ | 197 | L->allowhook = 0; /* cannot call hooks inside a hook */ |
198 | L->ci->callstatus |= CIST_HOOKED; | ||
199 | lua_unlock(L); | 199 | lua_unlock(L); |
200 | (*hook)(L, &ar); | 200 | (*hook)(L, &ar); |
201 | lua_lock(L); | 201 | lua_lock(L); |
@@ -203,7 +203,7 @@ void luaD_callhook (lua_State *L, int event, int line) { | |||
203 | L->allowhook = 1; | 203 | L->allowhook = 1; |
204 | L->ci->top = restorestack(L, ci_top); | 204 | L->ci->top = restorestack(L, ci_top); |
205 | L->top = restorestack(L, top); | 205 | L->top = restorestack(L, top); |
206 | L->ci->status &= ~1; /* this level is not running a hook anymore */ | 206 | L->ci->callstatus &= ~CIST_HOOKED; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
@@ -297,7 +297,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
297 | lua_assert(ci->top <= L->stack_last); | 297 | lua_assert(ci->top <= L->stack_last); |
298 | L->savedpc = p->code; /* starting point */ | 298 | L->savedpc = p->code; /* starting point */ |
299 | ci->tailcalls = 0; | 299 | ci->tailcalls = 0; |
300 | ci->status = 0; | 300 | ci->callstatus = CIST_LUA; |
301 | ci->nresults = nresults; | 301 | ci->nresults = nresults; |
302 | for (st = L->top; st < ci->top; st++) | 302 | for (st = L->top; st < ci->top; st++) |
303 | setnilvalue(st); | 303 | setnilvalue(st); |
@@ -319,6 +319,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
319 | ci->top = L->top + LUA_MINSTACK; | 319 | ci->top = L->top + LUA_MINSTACK; |
320 | lua_assert(ci->top <= L->stack_last); | 320 | lua_assert(ci->top <= L->stack_last); |
321 | ci->nresults = nresults; | 321 | ci->nresults = nresults; |
322 | ci->callstatus = 0; | ||
322 | if (L->hookmask & LUA_MASKCALL) | 323 | if (L->hookmask & LUA_MASKCALL) |
323 | luaD_callhook(L, LUA_HOOKCALL, -1); | 324 | luaD_callhook(L, LUA_HOOKCALL, -1); |
324 | lua_unlock(L); | 325 | lua_unlock(L); |
@@ -333,7 +334,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
333 | static StkId callrethooks (lua_State *L, StkId firstResult) { | 334 | static StkId callrethooks (lua_State *L, StkId firstResult) { |
334 | ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ | 335 | ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ |
335 | luaD_callhook(L, LUA_HOOKRET, -1); | 336 | luaD_callhook(L, LUA_HOOKRET, -1); |
336 | if (f_isLua(L->ci)) { /* Lua function? */ | 337 | if (isLua(L->ci)) { /* Lua function? */ |
337 | while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ | 338 | while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ |
338 | luaD_callhook(L, LUA_HOOKTAILRET, -1); | 339 | luaD_callhook(L, LUA_HOOKTAILRET, -1); |
339 | } | 340 | } |
@@ -381,7 +382,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
381 | luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ | 382 | luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ |
382 | } | 383 | } |
383 | if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ | 384 | if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ |
384 | luaV_execute(L, 1); /* call it */ | 385 | luaV_execute(L); /* call it */ |
385 | g->nCcalls--; | 386 | g->nCcalls--; |
386 | luaC_checkGC(L); | 387 | luaC_checkGC(L); |
387 | } | 388 | } |
@@ -398,7 +399,7 @@ static void resume (lua_State *L, void *ud) { | |||
398 | else { /* resuming from previous yield */ | 399 | else { /* resuming from previous yield */ |
399 | lua_assert(L->status == LUA_YIELD); | 400 | lua_assert(L->status == LUA_YIELD); |
400 | L->status = LUA_OK; | 401 | L->status = LUA_OK; |
401 | if (!f_isLua(ci)) { /* `common' yield? */ | 402 | if (!isLua(ci)) { /* `common' yield? */ |
402 | /* finish interrupted execution of `OP_CALL' */ | 403 | /* finish interrupted execution of `OP_CALL' */ |
403 | lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || | 404 | lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || |
404 | GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); | 405 | GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); |
@@ -408,7 +409,7 @@ static void resume (lua_State *L, void *ud) { | |||
408 | else /* yielded inside a hook: just continue its execution */ | 409 | else /* yielded inside a hook: just continue its execution */ |
409 | L->base = L->ci->base; | 410 | L->base = L->ci->base; |
410 | } | 411 | } |
411 | luaV_execute(L, cast_int(L->ci - L->base_ci)); | 412 | luaV_execute(L); |
412 | } | 413 | } |
413 | 414 | ||
414 | 415 | ||
@@ -461,7 +462,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) { | |||
461 | L->status = LUA_YIELD; | 462 | L->status = LUA_YIELD; |
462 | if (!isLua(L->ci)) /* not inside a hook? */ | 463 | if (!isLua(L->ci)) /* not inside a hook? */ |
463 | luaD_throw(L, LUA_YIELD); | 464 | luaD_throw(L, LUA_YIELD); |
464 | lua_assert(L->ci->status & 1); /* must be inside a hook */ | 465 | lua_assert(L->ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |
465 | lua_unlock(L); | 466 | lua_unlock(L); |
466 | return 0; /* otherwise, return to 'luaD_callhook' */ | 467 | return 0; /* otherwise, return to 'luaD_callhook' */ |
467 | } | 468 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.45 2008/06/26 19:42:45 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.46 2008/08/13 17:01:33 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -56,7 +56,7 @@ static void stack_init (lua_State *L1, lua_State *L) { | |||
56 | setnilvalue(L1->top++); /* `function' entry for this `ci' */ | 56 | setnilvalue(L1->top++); /* `function' entry for this `ci' */ |
57 | L1->base = L1->ci->base = L1->top; | 57 | L1->base = L1->ci->base = L1->top; |
58 | L1->ci->top = L1->top + LUA_MINSTACK; | 58 | L1->ci->top = L1->top + LUA_MINSTACK; |
59 | L1->ci->status = 0; | 59 | L1->ci->callstatus = 0; |
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.34 2008/06/26 19:42:45 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.35 2008/08/13 17:01:33 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -82,16 +82,23 @@ typedef struct CallInfo { | |||
82 | StkId top; /* top for this function */ | 82 | StkId top; /* top for this function */ |
83 | const Instruction *savedpc; | 83 | const Instruction *savedpc; |
84 | short nresults; /* expected number of results from this function */ | 84 | short nresults; /* expected number of results from this function */ |
85 | lu_byte status; | 85 | lu_byte callstatus; |
86 | int tailcalls; /* number of tail calls lost under this entry */ | 86 | int tailcalls; /* number of tail calls lost under this entry */ |
87 | } CallInfo; | 87 | } CallInfo; |
88 | 88 | ||
89 | 89 | ||
90 | /* | ||
91 | ** Bits in CallInfo status | ||
92 | */ | ||
93 | #define CIST_LUA 1 /* call is running a Lua function */ | ||
94 | #define CIST_HOOKED 2 /* call is running a debug hook */ | ||
95 | #define CIST_REENTRY 4 /* call is running on same invocation of | ||
96 | luaV_execute of previous call */ | ||
97 | |||
90 | 98 | ||
91 | #define curr_func(L) (clvalue(L->ci->func)) | 99 | #define curr_func(L) (clvalue(L->ci->func)) |
92 | #define ci_func(ci) (clvalue((ci)->func)) | 100 | #define ci_func(ci) (clvalue((ci)->func)) |
93 | #define f_isLua(ci) (!ci_func(ci)->c.isC) | 101 | #define isLua(ci) ((ci)->callstatus & CIST_LUA) |
94 | #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) | ||
95 | 102 | ||
96 | 103 | ||
97 | /* | 104 | /* |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.53 2008/06/26 19:42:45 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.54 2008/08/13 17:02:12 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -349,7 +349,7 @@ printf(">>> %d %s %02x\n", g->gcstate, luaT_typenames[gch(o)->tt], gch(o)->mar | |||
349 | 349 | ||
350 | 350 | ||
351 | int lua_checkpc (lua_State *L, pCallInfo ci) { | 351 | int lua_checkpc (lua_State *L, pCallInfo ci) { |
352 | if (ci == L->base_ci || !f_isLua(ci)) return 1; | 352 | if (ci == L->base_ci || !isLua(ci)) return 1; |
353 | else { | 353 | else { |
354 | Proto *p = ci_func(ci)->l.p; | 354 | Proto *p = ci_func(ci)->l.p; |
355 | if (ci < L->ci) | 355 | if (ci < L->ci) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.74 2008/04/02 16:16:06 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.75 2008/08/13 17:02:42 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 | */ |
@@ -280,11 +280,14 @@ void luaV_concat (lua_State *L, int total, int last) { | |||
280 | if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { | 280 | if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { |
281 | if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) | 281 | if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) |
282 | luaG_concaterror(L, top-2, top-1); | 282 | luaG_concaterror(L, top-2, top-1); |
283 | } else if (tsvalue(top-1)->len == 0) { /* second operand is empty? */ | 283 | } |
284 | else if (tsvalue(top-1)->len == 0) { /* second operand is empty? */ | ||
284 | (void)tostring(L, top - 2); /* result is first operand */ ; | 285 | (void)tostring(L, top - 2); /* result is first operand */ ; |
285 | } else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) { | 286 | } |
287 | else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) { | ||
286 | setsvalue2s(L, top-2, rawtsvalue(top-1)); /* result is second op. */ | 288 | setsvalue2s(L, top-2, rawtsvalue(top-1)); /* result is second op. */ |
287 | } else { | 289 | } |
290 | else { | ||
288 | /* at least two (non-empty) string values; get as many as possible */ | 291 | /* at least two (non-empty) string values; get as many as possible */ |
289 | size_t tl = tsvalue(top-1)->len; | 292 | size_t tl = tsvalue(top-1)->len; |
290 | char *buffer; | 293 | char *buffer; |
@@ -397,7 +400,7 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, | |||
397 | 400 | ||
398 | 401 | ||
399 | 402 | ||
400 | void luaV_execute (lua_State *L, int nexeccalls) { | 403 | void luaV_execute (lua_State *L) { |
401 | LClosure *cl; | 404 | LClosure *cl; |
402 | StkId base; | 405 | StkId base; |
403 | TValue *k; | 406 | TValue *k; |
@@ -601,7 +604,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
601 | continue; | 604 | continue; |
602 | } | 605 | } |
603 | else { /* Lua function */ | 606 | else { /* Lua function */ |
604 | nexeccalls++; | 607 | L->ci->callstatus |= CIST_REENTRY; |
605 | goto reentry; /* restart luaV_execute over new Lua function */ | 608 | goto reentry; /* restart luaV_execute over new Lua function */ |
606 | } | 609 | } |
607 | } | 610 | } |
@@ -636,9 +639,9 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
636 | if (b != 0) L->top = ra+b-1; | 639 | if (b != 0) L->top = ra+b-1; |
637 | if (L->openupval) luaF_close(L, base); | 640 | if (L->openupval) luaF_close(L, base); |
638 | b = luaD_poscall(L, ra); | 641 | b = luaD_poscall(L, ra); |
639 | if (--nexeccalls == 0) /* was previous function running `here'? */ | 642 | if (!((L->ci + 1)->callstatus & CIST_REENTRY)) |
640 | return; /* no: return */ | 643 | return; /* external invocation: return */ |
641 | else { /* yes: continue its execution */ | 644 | else { /* invocation via reentry: continue execution */ |
642 | if (b) L->top = L->ci->top; | 645 | if (b) L->top = L->ci->top; |
643 | lua_assert(isLua(L->ci)); | 646 | lua_assert(isLua(L->ci)); |
644 | lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); | 647 | lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.h,v 2.5 2005/08/22 18:54:49 roberto Exp roberto $ | 2 | ** $Id: lvm.h,v 2.6 2007/02/09 13:04:52 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 | */ |
@@ -32,7 +32,7 @@ LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, | |||
32 | StkId val); | 32 | StkId val); |
33 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, | 33 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, |
34 | StkId val); | 34 | StkId val); |
35 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); | 35 | LUAI_FUNC void luaV_execute (lua_State *L); |
36 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); | 36 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); |
37 | 37 | ||
38 | #endif | 38 | #endif |