diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-08-09 16:49:04 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-08-09 16:49:04 -0300 |
commit | 44b19075c0fa4310d312147ee1d74dc11ff36eba (patch) | |
tree | da10448271a24dc9f0f24e5123fdf8918f9c7228 | |
parent | ab3dfa55948a670c35152ffd965d218ad48f871a (diff) | |
download | lua-44b19075c0fa4310d312147ee1d74dc11ff36eba.tar.gz lua-44b19075c0fa4310d312147ee1d74dc11ff36eba.tar.bz2 lua-44b19075c0fa4310d312147ee1d74dc11ff36eba.zip |
small changes (to easy integration with Coco)
-rw-r--r-- | ldo.c | 31 | ||||
-rw-r--r-- | lvm.c | 16 |
2 files changed, 21 insertions, 26 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.27 2005/06/13 21:17:59 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.28 2005/07/11 14:00:31 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 | */ |
@@ -298,6 +298,11 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
298 | for (st = L->top; st < ci->top; st++) | 298 | for (st = L->top; st < ci->top; st++) |
299 | setnilvalue(st); | 299 | setnilvalue(st); |
300 | L->top = ci->top; | 300 | L->top = ci->top; |
301 | if (L->hookmask & LUA_MASKCALL) { | ||
302 | L->savedpc++; /* hooks assume 'pc' is already incremented */ | ||
303 | luaD_callhook(L, LUA_HOOKCALL, -1); | ||
304 | L->savedpc--; /* correct 'pc' */ | ||
305 | } | ||
301 | return PCRLUA; | 306 | return PCRLUA; |
302 | } | 307 | } |
303 | else { /* if is a C function, call it */ | 308 | else { /* if is a C function, call it */ |
@@ -380,11 +385,11 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
380 | 385 | ||
381 | static void resume (lua_State *L, void *ud) { | 386 | static void resume (lua_State *L, void *ud) { |
382 | StkId firstResult; | 387 | StkId firstResult; |
383 | int nargs = *cast(int *, ud); | 388 | StkId firstArg = cast(StkId, ud); |
384 | CallInfo *ci = L->ci; | 389 | CallInfo *ci = L->ci; |
385 | if (L->status != LUA_YIELD) { | 390 | if (L->status != LUA_YIELD) { |
386 | lua_assert(ci == L->base_ci && nargs < L->top - L->base); | 391 | lua_assert(ci == L->base_ci && firstArg > L->base); |
387 | luaD_precall(L, L->top - (nargs + 1), LUA_MULTRET); /* start coroutine */ | 392 | luaD_precall(L, firstArg - 1, LUA_MULTRET); /* start coroutine */ |
388 | } | 393 | } |
389 | else { /* resuming from previous yield */ | 394 | else { /* resuming from previous yield */ |
390 | if (!f_isLua(ci)) { /* `common' yield? */ | 395 | if (!f_isLua(ci)) { /* `common' yield? */ |
@@ -392,9 +397,12 @@ static void resume (lua_State *L, void *ud) { | |||
392 | int nresults = ci->nresults; | 397 | int nresults = ci->nresults; |
393 | lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || | 398 | lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || |
394 | GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); | 399 | GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); |
395 | luaD_poscall(L, nresults, L->top - nargs); /* complete it */ | 400 | luaD_poscall(L, nresults, firstArg); /* complete it */ |
396 | if (nresults >= 0) L->top = L->ci->top; | 401 | if (nresults >= 0) L->top = L->ci->top; |
397 | } /* else yielded inside a hook: just continue its execution */ | 402 | } |
403 | else { /* yielded inside a hook: just continue its execution */ | ||
404 | L->base = L->ci->base; | ||
405 | } | ||
398 | } | 406 | } |
399 | L->status = 0; | 407 | L->status = 0; |
400 | firstResult = luaV_execute(L, cast(int, L->ci - L->base_ci)); | 408 | firstResult = luaV_execute(L, cast(int, L->ci - L->base_ci)); |
@@ -423,7 +431,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { | |||
423 | else if (L->ci != L->base_ci) | 431 | else if (L->ci != L->base_ci) |
424 | return resume_error(L, "cannot resume non-suspended coroutine"); | 432 | return resume_error(L, "cannot resume non-suspended coroutine"); |
425 | } | 433 | } |
426 | status = luaD_rawrunprotected(L, resume, &nargs); | 434 | status = luaD_rawrunprotected(L, resume, L->top - nargs); |
427 | if (status != 0) { /* error? */ | 435 | if (status != 0) { /* error? */ |
428 | L->status = cast(lu_byte, status); /* mark thread as `dead' */ | 436 | L->status = cast(lu_byte, status); /* mark thread as `dead' */ |
429 | seterrorobj(L, status, L->top); | 437 | seterrorobj(L, status, L->top); |
@@ -441,14 +449,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) { | |||
441 | ci = L->ci; | 449 | ci = L->ci; |
442 | if (L->nCcalls > 0) | 450 | if (L->nCcalls > 0) |
443 | luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); | 451 | luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); |
444 | if (!f_isLua(ci)) { /* usual yield */ | 452 | L->base = L->top - nresults; /* protect stack slots below */ |
445 | if (L->top - nresults > L->base) { /* is there garbage in the stack? */ | ||
446 | int i; | ||
447 | for (i=0; i<nresults; i++) /* move down results */ | ||
448 | setobjs2s(L, L->base + i, L->top - nresults + i); | ||
449 | L->top = L->base + nresults; | ||
450 | } | ||
451 | } /* else it's an yield inside a hook: nothing to do */ | ||
452 | L->status = LUA_YIELD; | 453 | L->status = LUA_YIELD; |
453 | lua_unlock(L); | 454 | lua_unlock(L); |
454 | return -1; | 455 | return -1; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.48 2005/07/05 14:31:20 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.49 2005/08/09 17:42:02 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 | */ |
@@ -362,13 +362,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
362 | StkId base; | 362 | StkId base; |
363 | TValue *k; | 363 | TValue *k; |
364 | const Instruction *pc; | 364 | const Instruction *pc; |
365 | callentry: /* entry point when calling new functions */ | 365 | reentry: /* entry point */ |
366 | if (L->hookmask & LUA_MASKCALL) { | ||
367 | L->savedpc++; /* hooks assume 'pc' is already incremented */ | ||
368 | luaD_callhook(L, LUA_HOOKCALL, -1); | ||
369 | L->savedpc--; /* correct 'pc' */ | ||
370 | } | ||
371 | retentry: /* entry point when returning to old functions */ | ||
372 | pc = L->savedpc; | 366 | pc = L->savedpc; |
373 | cl = &clvalue(L->ci->func)->l; | 367 | cl = &clvalue(L->ci->func)->l; |
374 | base = L->base; | 368 | base = L->base; |
@@ -618,7 +612,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
618 | switch (luaD_precall(L, ra, nresults)) { | 612 | switch (luaD_precall(L, ra, nresults)) { |
619 | case PCRLUA: { | 613 | case PCRLUA: { |
620 | nexeccalls++; | 614 | nexeccalls++; |
621 | goto callentry; /* restart luaV_execute over new Lua function */ | 615 | goto reentry; /* restart luaV_execute over new Lua function */ |
622 | } | 616 | } |
623 | case PCRC: { | 617 | case PCRC: { |
624 | /* it was a C function (`precall' called it); adjust results */ | 618 | /* it was a C function (`precall' called it); adjust results */ |
@@ -652,7 +646,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
652 | ci->savedpc = L->savedpc; | 646 | ci->savedpc = L->savedpc; |
653 | ci->tailcalls++; /* one more call lost */ | 647 | ci->tailcalls++; /* one more call lost */ |
654 | L->ci--; /* remove new frame */ | 648 | L->ci--; /* remove new frame */ |
655 | goto callentry; | 649 | goto reentry; |
656 | } | 650 | } |
657 | case PCRC: { | 651 | case PCRC: { |
658 | /* it was a C function (`precall' called it) */ | 652 | /* it was a C function (`precall' called it) */ |
@@ -677,7 +671,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
677 | lua_assert(GET_OPCODE(*((L->ci - 1)->savedpc - 1)) == OP_CALL); | 671 | lua_assert(GET_OPCODE(*((L->ci - 1)->savedpc - 1)) == OP_CALL); |
678 | luaD_poscall(L, nresults, ra); | 672 | luaD_poscall(L, nresults, ra); |
679 | if (nresults >= 0) L->top = L->ci->top; | 673 | if (nresults >= 0) L->top = L->ci->top; |
680 | goto retentry; | 674 | goto reentry; |
681 | } | 675 | } |
682 | } | 676 | } |
683 | case OP_FORLOOP: { | 677 | case OP_FORLOOP: { |