diff options
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 35 |
1 files changed, 18 insertions, 17 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.228 2003/10/20 17:42:41 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.229 2003/11/11 16:34:17 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 | */ |
| @@ -64,16 +64,16 @@ struct lua_longjmp { | |||
| 64 | static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { | 64 | static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { |
| 65 | switch (errcode) { | 65 | switch (errcode) { |
| 66 | case LUA_ERRMEM: { | 66 | case LUA_ERRMEM: { |
| 67 | setsvalue2s(oldtop, luaS_newliteral(L, MEMERRMSG)); | 67 | setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); |
| 68 | break; | 68 | break; |
| 69 | } | 69 | } |
| 70 | case LUA_ERRERR: { | 70 | case LUA_ERRERR: { |
| 71 | setsvalue2s(oldtop, luaS_newliteral(L, "error in error handling")); | 71 | setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); |
| 72 | break; | 72 | break; |
| 73 | } | 73 | } |
| 74 | case LUA_ERRSYNTAX: | 74 | case LUA_ERRSYNTAX: |
| 75 | case LUA_ERRRUN: { | 75 | case LUA_ERRRUN: { |
| 76 | setobjs2s(oldtop, L->top - 1); /* error message on current top */ | 76 | setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ |
| 77 | break; | 77 | break; |
| 78 | } | 78 | } |
| 79 | } | 79 | } |
| @@ -118,12 +118,12 @@ static void restore_stack_limit (lua_State *L) { | |||
| 118 | /* }====================================================== */ | 118 | /* }====================================================== */ |
| 119 | 119 | ||
| 120 | 120 | ||
| 121 | static void correctstack (lua_State *L, TObject *oldstack) { | 121 | static void correctstack (lua_State *L, TValue *oldstack) { |
| 122 | CallInfo *ci; | 122 | CallInfo *ci; |
| 123 | GCObject *up; | 123 | GCObject *up; |
| 124 | L->top = (L->top - oldstack) + L->stack; | 124 | L->top = (L->top - oldstack) + L->stack; |
| 125 | for (up = L->openupval; up != NULL; up = up->gch.next) | 125 | for (up = L->openupval; up != NULL; up = up->gch.next) |
| 126 | gcotouv(up)->v = (gcotouv(up)->v - oldstack) + L->stack; | 126 | gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; |
| 127 | for (ci = L->base_ci; ci <= L->ci; ci++) { | 127 | for (ci = L->base_ci; ci <= L->ci; ci++) { |
| 128 | ci->top = (ci->top - oldstack) + L->stack; | 128 | ci->top = (ci->top - oldstack) + L->stack; |
| 129 | ci->base = (ci->base - oldstack) + L->stack; | 129 | ci->base = (ci->base - oldstack) + L->stack; |
| @@ -133,8 +133,8 @@ static void correctstack (lua_State *L, TObject *oldstack) { | |||
| 133 | 133 | ||
| 134 | 134 | ||
| 135 | void luaD_reallocstack (lua_State *L, int newsize) { | 135 | void luaD_reallocstack (lua_State *L, int newsize) { |
| 136 | TObject *oldstack = L->stack; | 136 | TValue *oldstack = L->stack; |
| 137 | luaM_reallocvector(L, L->stack, L->stacksize, newsize, TObject); | 137 | luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue); |
| 138 | L->stacksize = newsize; | 138 | L->stacksize = newsize; |
| 139 | L->stack_last = L->stack+newsize-1-EXTRA_STACK; | 139 | L->stack_last = L->stack+newsize-1-EXTRA_STACK; |
| 140 | correctstack(L, oldstack); | 140 | correctstack(L, oldstack); |
| @@ -207,27 +207,28 @@ static void adjust_varargs (lua_State *L, int nfixargs, StkId base) { | |||
| 207 | actual -= nfixargs; /* number of extra arguments */ | 207 | actual -= nfixargs; /* number of extra arguments */ |
| 208 | htab = luaH_new(L, actual, 1); /* create `arg' table */ | 208 | htab = luaH_new(L, actual, 1); /* create `arg' table */ |
| 209 | for (i=0; i<actual; i++) /* put extra arguments into `arg' table */ | 209 | for (i=0; i<actual; i++) /* put extra arguments into `arg' table */ |
| 210 | setobj2n(luaH_setnum(L, htab, i+1), L->top - actual + i); | 210 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - actual + i); |
| 211 | /* store counter in field `n' */ | 211 | /* store counter in field `n' */ |
| 212 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), | 212 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), |
| 213 | cast(lua_Number, actual)); | 213 | cast(lua_Number, actual)); |
| 214 | L->top -= actual; /* remove extra elements from the stack */ | 214 | L->top -= actual; /* remove extra elements from the stack */ |
| 215 | sethvalue(L->top, htab); | 215 | sethvalue(L, L->top, htab); |
| 216 | lua_assert(iswhite(obj2gco(htab))); | ||
| 216 | incr_top(L); | 217 | incr_top(L); |
| 217 | } | 218 | } |
| 218 | 219 | ||
| 219 | 220 | ||
| 220 | static StkId tryfuncTM (lua_State *L, StkId func) { | 221 | static StkId tryfuncTM (lua_State *L, StkId func) { |
| 221 | const TObject *tm = luaT_gettmbyobj(L, func, TM_CALL); | 222 | const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); |
| 222 | StkId p; | 223 | StkId p; |
| 223 | ptrdiff_t funcr = savestack(L, func); | 224 | ptrdiff_t funcr = savestack(L, func); |
| 224 | if (!ttisfunction(tm)) | 225 | if (!ttisfunction(tm)) |
| 225 | luaG_typeerror(L, func, "call"); | 226 | luaG_typeerror(L, func, "call"); |
| 226 | /* Open a hole inside the stack at `func' */ | 227 | /* Open a hole inside the stack at `func' */ |
| 227 | for (p = L->top; p > func; p--) setobjs2s(p, p-1); | 228 | for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); |
| 228 | incr_top(L); | 229 | incr_top(L); |
| 229 | func = restorestack(L, funcr); /* previous call may change stack */ | 230 | func = restorestack(L, funcr); /* previous call may change stack */ |
| 230 | setobj2s(func, tm); /* tag method is the new function to be called */ | 231 | setobj2s(L, func, tm); /* tag method is the new function to be called */ |
| 231 | return func; | 232 | return func; |
| 232 | } | 233 | } |
| 233 | 234 | ||
| @@ -294,7 +295,7 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { | |||
| 294 | L->base = L->ci->base; /* restore base */ | 295 | L->base = L->ci->base; /* restore base */ |
| 295 | /* move results to correct place */ | 296 | /* move results to correct place */ |
| 296 | while (wanted != 0 && firstResult < L->top) { | 297 | while (wanted != 0 && firstResult < L->top) { |
| 297 | setobjs2s(res++, firstResult++); | 298 | setobjs2s(L, res++, firstResult++); |
| 298 | wanted--; | 299 | wanted--; |
| 299 | } | 300 | } |
| 300 | while (wanted-- > 0) | 301 | while (wanted-- > 0) |
| @@ -354,7 +355,7 @@ static void resume (lua_State *L, void *ud) { | |||
| 354 | 355 | ||
| 355 | static int resume_error (lua_State *L, const char *msg) { | 356 | static int resume_error (lua_State *L, const char *msg) { |
| 356 | L->top = L->ci->base; | 357 | L->top = L->ci->base; |
| 357 | setsvalue2s(L->top, luaS_new(L, msg)); | 358 | setsvalue2s(L, L->top, luaS_new(L, msg)); |
| 358 | incr_top(L); | 359 | incr_top(L); |
| 359 | lua_unlock(L); | 360 | lua_unlock(L); |
| 360 | return LUA_ERRRUN; | 361 | return LUA_ERRRUN; |
| @@ -400,7 +401,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) { | |||
| 400 | if (L->top - nresults > L->base) { /* is there garbage in the stack? */ | 401 | if (L->top - nresults > L->base) { /* is there garbage in the stack? */ |
| 401 | int i; | 402 | int i; |
| 402 | for (i=0; i<nresults; i++) /* move down results */ | 403 | for (i=0; i<nresults; i++) /* move down results */ |
| 403 | setobjs2s(L->base + i, L->top - nresults + i); | 404 | setobjs2s(L, L->base + i, L->top - nresults + i); |
| 404 | L->top = L->base + nresults; | 405 | L->top = L->base + nresults; |
| 405 | } | 406 | } |
| 406 | } /* else it's an yield inside a hook: nothing to do */ | 407 | } /* else it's an yield inside a hook: nothing to do */ |
| @@ -457,7 +458,7 @@ static void f_parser (lua_State *L, void *ud) { | |||
| 457 | cl->l.p = tf; | 458 | cl->l.p = tf; |
| 458 | for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ | 459 | for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ |
| 459 | cl->l.upvals[i] = luaF_newupval(L); | 460 | cl->l.upvals[i] = luaF_newupval(L); |
| 460 | setclvalue(L->top, cl); | 461 | setclvalue(L, L->top, cl); |
| 461 | incr_top(L); | 462 | incr_top(L); |
| 462 | } | 463 | } |
| 463 | 464 | ||
