diff options
-rw-r--r-- | lapi.c | 30 | ||||
-rw-r--r-- | ldebug.c | 55 | ||||
-rw-r--r-- | ldo.c | 27 | ||||
-rw-r--r-- | lstate.c | 3 | ||||
-rw-r--r-- | lstate.h | 5 | ||||
-rw-r--r-- | ltests.c | 6 | ||||
-rw-r--r-- | lvm.c | 35 |
7 files changed, 81 insertions, 80 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.76 2009/04/17 22:00:01 roberto Exp $ | 2 | ** $Id: lapi.c,v 2.76 2009/04/17 22:00:01 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -35,20 +35,21 @@ const char lua_ident[] = | |||
35 | 35 | ||
36 | 36 | ||
37 | 37 | ||
38 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) | 38 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func)) |
39 | 39 | ||
40 | #define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) | 40 | #define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) |
41 | 41 | ||
42 | 42 | ||
43 | static TValue *index2adr (lua_State *L, int idx) { | 43 | static TValue *index2adr (lua_State *L, int idx) { |
44 | CallInfo *ci = L->ci; | ||
44 | if (idx > 0) { | 45 | if (idx > 0) { |
45 | TValue *o = L->base + (idx - 1); | 46 | TValue *o = ci->func + idx; |
46 | api_check(L, idx <= L->ci->top - L->base); | 47 | api_check(L, idx <= ci->top - (ci->func + 1)); |
47 | if (o >= L->top) return cast(TValue *, luaO_nilobject); | 48 | if (o >= L->top) return cast(TValue *, luaO_nilobject); |
48 | else return o; | 49 | else return o; |
49 | } | 50 | } |
50 | else if (idx > LUA_REGISTRYINDEX) { | 51 | else if (idx > LUA_REGISTRYINDEX) { |
51 | api_check(L, idx != 0 && -idx <= L->top - L->base); | 52 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1)); |
52 | return L->top + idx; | 53 | return L->top + idx; |
53 | } | 54 | } |
54 | else switch (idx) { /* pseudo-indices */ | 55 | else switch (idx) { /* pseudo-indices */ |
@@ -83,13 +84,15 @@ static Table *getcurrenv (lua_State *L) { | |||
83 | 84 | ||
84 | LUA_API int lua_checkstack (lua_State *L, int size) { | 85 | LUA_API int lua_checkstack (lua_State *L, int size) { |
85 | int res = 1; | 86 | int res = 1; |
87 | CallInfo *ci = L->ci; | ||
86 | lua_lock(L); | 88 | lua_lock(L); |
87 | if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) | 89 | if (size > LUAI_MAXCSTACK || |
90 | (L->top - (ci->func + 1) + size) > LUAI_MAXCSTACK) | ||
88 | res = 0; /* stack overflow */ | 91 | res = 0; /* stack overflow */ |
89 | else if (size > 0) { | 92 | else if (size > 0) { |
90 | luaD_checkstack(L, size); | 93 | luaD_checkstack(L, size); |
91 | if (L->ci->top < L->top + size) | 94 | if (ci->top < L->top + size) |
92 | L->ci->top = L->top + size; | 95 | ci->top = L->top + size; |
93 | } | 96 | } |
94 | lua_unlock(L); | 97 | lua_unlock(L); |
95 | return res; | 98 | return res; |
@@ -138,20 +141,21 @@ LUA_API void lua_checkversion_ (lua_State *L, int version) { | |||
138 | 141 | ||
139 | 142 | ||
140 | LUA_API int lua_gettop (lua_State *L) { | 143 | LUA_API int lua_gettop (lua_State *L) { |
141 | return cast_int(L->top - L->base); | 144 | return cast_int(L->top - (L->ci->func + 1)); |
142 | } | 145 | } |
143 | 146 | ||
144 | 147 | ||
145 | LUA_API void lua_settop (lua_State *L, int idx) { | 148 | LUA_API void lua_settop (lua_State *L, int idx) { |
149 | StkId func = L->ci->func; | ||
146 | lua_lock(L); | 150 | lua_lock(L); |
147 | if (idx >= 0) { | 151 | if (idx >= 0) { |
148 | api_check(L, idx <= L->stack_last - L->base); | 152 | api_check(L, idx <= L->stack_last - (func + 1)); |
149 | while (L->top < L->base + idx) | 153 | while (L->top < (func + 1) + idx) |
150 | setnilvalue(L->top++); | 154 | setnilvalue(L->top++); |
151 | L->top = L->base + idx; | 155 | L->top = (func + 1) + idx; |
152 | } | 156 | } |
153 | else { | 157 | else { |
154 | api_check(L, -(idx+1) <= (L->top - L->base)); | 158 | api_check(L, -(idx+1) <= (L->top - (func + 1))); |
155 | L->top += idx+1; /* `subtract' index (index is negative) */ | 159 | L->top += idx+1; /* `subtract' index (index is negative) */ |
156 | } | 160 | } |
157 | lua_unlock(L); | 161 | lua_unlock(L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.49 2009/04/30 17:42:21 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.50 2009/05/04 18:26:21 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 | */ |
@@ -103,32 +103,34 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | |||
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
106 | static Proto *getluaproto (CallInfo *ci) { | 106 | static const char *findlocal (lua_State *L, CallInfo *ci, int n, |
107 | return (isLua(ci) ? ci_func(ci)->l.p : NULL); | 107 | StkId *pos) { |
108 | } | 108 | const char *name = NULL; |
109 | 109 | StkId base; | |
110 | 110 | if (isLua(ci)) { | |
111 | static const char *findlocal (lua_State *L, CallInfo *ci, int n) { | 111 | base = ci->u.l.base; |
112 | const char *name; | 112 | name = luaF_getlocalname(ci_func(ci)->l.p, n, currentpc(ci)); |
113 | Proto *fp = getluaproto(ci); | 113 | } |
114 | if (fp && (name = luaF_getlocalname(fp, n, currentpc(ci))) != NULL) | 114 | else |
115 | return name; /* is a local variable in a Lua function */ | 115 | base = ci->func + 1; |
116 | else { | 116 | if (name == NULL) { /* no 'standard' name? */ |
117 | StkId limit = (ci == L->ci) ? L->top : ci->next->func; | 117 | StkId limit = (ci == L->ci) ? L->top : ci->next->func; |
118 | if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ | 118 | if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */ |
119 | return "(*temporary)"; | 119 | name = "(*temporary)"; /* generic name for any valid slot */ |
120 | else | 120 | else return NULL; /* no name */ |
121 | return NULL; | ||
122 | } | 121 | } |
122 | *pos = base + (n - 1); | ||
123 | return name; | ||
123 | } | 124 | } |
124 | 125 | ||
125 | 126 | ||
126 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | 127 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { |
127 | CallInfo *ci = ar->i_ci; | 128 | CallInfo *ci = ar->i_ci; |
128 | const char *name = findlocal(L, ci, n); | 129 | StkId pos; |
130 | const char *name = findlocal(L, ci, n, &pos); | ||
129 | lua_lock(L); | 131 | lua_lock(L); |
130 | if (name) { | 132 | if (name) { |
131 | setobj2s(L, L->top, ci->base + (n - 1)); | 133 | setobj2s(L, L->top, pos); |
132 | api_incr_top(L); | 134 | api_incr_top(L); |
133 | } | 135 | } |
134 | lua_unlock(L); | 136 | lua_unlock(L); |
@@ -138,10 +140,11 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
138 | 140 | ||
139 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | 141 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { |
140 | CallInfo *ci = ar->i_ci; | 142 | CallInfo *ci = ar->i_ci; |
141 | const char *name = findlocal(L, ci, n); | 143 | StkId pos; |
144 | const char *name = findlocal(L, ci, n, &pos); | ||
142 | lua_lock(L); | 145 | lua_lock(L); |
143 | if (name) | 146 | if (name) |
144 | setobjs2s(L, ci->base + (n - 1), L->top - 1); | 147 | setobjs2s(L, pos, L->top - 1); |
145 | L->top--; /* pop value */ | 148 | L->top--; /* pop value */ |
146 | lua_unlock(L); | 149 | lua_unlock(L); |
147 | return name; | 150 | return name; |
@@ -282,8 +285,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |||
282 | Proto *p; | 285 | Proto *p; |
283 | int lastpc, pc; | 286 | int lastpc, pc; |
284 | const char *what = NULL; | 287 | const char *what = NULL; |
285 | if (!isLua(ci)) /* is not a Lua function? */ | 288 | lua_assert(isLua(ci)); |
286 | return NULL; /* cannot find name for it */ | ||
287 | p = ci_func(ci)->l.p; | 289 | p = ci_func(ci)->l.p; |
288 | lastpc = currentpc(ci); | 290 | lastpc = currentpc(ci); |
289 | *name = luaF_getlocalname(p, reg + 1, lastpc); | 291 | *name = luaF_getlocalname(p, reg + 1, lastpc); |
@@ -418,17 +420,18 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | |||
418 | /* only ANSI way to check whether a pointer points to an array */ | 420 | /* only ANSI way to check whether a pointer points to an array */ |
419 | static int isinstack (CallInfo *ci, const TValue *o) { | 421 | static int isinstack (CallInfo *ci, const TValue *o) { |
420 | StkId p; | 422 | StkId p; |
421 | for (p = ci->base; p < ci->top; p++) | 423 | for (p = ci->u.l.base; p < ci->top; p++) |
422 | if (o == p) return 1; | 424 | if (o == p) return 1; |
423 | return 0; | 425 | return 0; |
424 | } | 426 | } |
425 | 427 | ||
426 | 428 | ||
427 | void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { | 429 | void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { |
430 | CallInfo *ci = L->ci; | ||
428 | const char *name = NULL; | 431 | const char *name = NULL; |
429 | const char *t = luaT_typenames[ttype(o)]; | 432 | const char *t = luaT_typenames[ttype(o)]; |
430 | const char *kind = (isinstack(L->ci, o)) ? | 433 | const char *kind = (isLua(ci) && isinstack(ci, o)) ? |
431 | getobjname(L, L->ci, cast_int(o - L->base), &name) : | 434 | getobjname(L, ci, cast_int(o - ci->u.l.base), &name) : |
432 | NULL; | 435 | NULL; |
433 | if (kind) | 436 | if (kind) |
434 | luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", | 437 | luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", |
@@ -469,7 +472,7 @@ static void addinfo (lua_State *L, const char *msg) { | |||
469 | if (isLua(ci)) { /* is Lua code? */ | 472 | if (isLua(ci)) { /* is Lua code? */ |
470 | char buff[LUA_IDSIZE]; /* add file:line information */ | 473 | char buff[LUA_IDSIZE]; /* add file:line information */ |
471 | int line = currentline(ci); | 474 | int line = currentline(ci); |
472 | luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); | 475 | luaO_chunkid(buff, getstr(ci_func(ci)->l.p->source), LUA_IDSIZE); |
473 | luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); | 476 | luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); |
474 | } | 477 | } |
475 | } | 478 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.63 2009/04/28 19:04:36 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.64 2009/05/21 20:06:11 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 | */ |
@@ -123,10 +123,10 @@ static void correctstack (lua_State *L, TValue *oldstack) { | |||
123 | gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; | 123 | gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; |
124 | for (ci = L->ci; ci != NULL; ci = ci->previous) { | 124 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
125 | ci->top = (ci->top - oldstack) + L->stack; | 125 | ci->top = (ci->top - oldstack) + L->stack; |
126 | ci->base = (ci->base - oldstack) + L->stack; | ||
127 | ci->func = (ci->func - oldstack) + L->stack; | 126 | ci->func = (ci->func - oldstack) + L->stack; |
127 | if (isLua(ci)) | ||
128 | ci->u.l.base = (ci->u.l.base - oldstack) + L->stack; | ||
128 | } | 129 | } |
129 | L->base = (L->base - oldstack) + L->stack; | ||
130 | } | 130 | } |
131 | 131 | ||
132 | 132 | ||
@@ -245,8 +245,8 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
245 | base = adjust_varargs(L, p, nargs); | 245 | base = adjust_varargs(L, p, nargs); |
246 | ci = next_ci(L); /* now 'enter' new function */ | 246 | ci = next_ci(L); /* now 'enter' new function */ |
247 | ci->func = func; | 247 | ci->func = func; |
248 | L->base = ci->base = base; | 248 | ci->u.l.base = base; |
249 | ci->top = L->base + p->maxstacksize; | 249 | ci->top = base + p->maxstacksize; |
250 | lua_assert(ci->top <= L->stack_last); | 250 | lua_assert(ci->top <= L->stack_last); |
251 | ci->u.l.savedpc = p->code; /* starting point */ | 251 | ci->u.l.savedpc = p->code; /* starting point */ |
252 | ci->u.l.tailcalls = 0; | 252 | ci->u.l.tailcalls = 0; |
@@ -265,7 +265,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
265 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 265 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
266 | ci = next_ci(L); /* now 'enter' new function */ | 266 | ci = next_ci(L); /* now 'enter' new function */ |
267 | ci->func = restorestack(L, funcr); | 267 | ci->func = restorestack(L, funcr); |
268 | L->base = ci->base = ci->func + 1; | ||
269 | ci->top = L->top + LUA_MINSTACK; | 268 | ci->top = L->top + LUA_MINSTACK; |
270 | lua_assert(ci->top <= L->stack_last); | 269 | lua_assert(ci->top <= L->stack_last); |
271 | ci->callstatus = 0; | 270 | ci->callstatus = 0; |
@@ -303,7 +302,6 @@ int luaD_poscall (lua_State *L, StkId firstResult) { | |||
303 | res = ci->func; /* res == final position of 1st result */ | 302 | res = ci->func; /* res == final position of 1st result */ |
304 | L->ci = ci = ci->previous; /* back to caller */ | 303 | L->ci = ci = ci->previous; /* back to caller */ |
305 | wanted = ci->nresults; | 304 | wanted = ci->nresults; |
306 | L->base = ci->base; /* restore base */ | ||
307 | /* move results to correct place */ | 305 | /* move results to correct place */ |
308 | for (i = wanted; i != 0 && firstResult < L->top; i--) | 306 | for (i = wanted; i != 0 && firstResult < L->top; i--) |
309 | setobjs2s(L, res++, firstResult++); | 307 | setobjs2s(L, res++, firstResult++); |
@@ -378,17 +376,15 @@ static void resume (lua_State *L, void *ud) { | |||
378 | StkId firstArg = cast(StkId, ud); | 376 | StkId firstArg = cast(StkId, ud); |
379 | CallInfo *ci = L->ci; | 377 | CallInfo *ci = L->ci; |
380 | if (L->status == LUA_OK) { /* start coroutine? */ | 378 | if (L->status == LUA_OK) { /* start coroutine? */ |
381 | lua_assert(ci == &L->base_ci && firstArg > L->base); | 379 | lua_assert(ci == &L->base_ci); |
382 | if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */ | 380 | if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */ |
383 | luaV_execute(L); /* call it */ | 381 | luaV_execute(L); /* call it */ |
384 | } | 382 | } |
385 | else { /* resuming from previous yield */ | 383 | else { /* resuming from previous yield */ |
386 | lua_assert(L->status == LUA_YIELD); | 384 | lua_assert(L->status == LUA_YIELD); |
387 | L->status = LUA_OK; | 385 | L->status = LUA_OK; |
388 | if (isLua(ci)) { /* yielded inside a hook? */ | 386 | if (isLua(ci)) /* yielded inside a hook? */ |
389 | L->base = ci->base; /* just continue its execution */ | ||
390 | luaV_execute(L); | 387 | luaV_execute(L); |
391 | } | ||
392 | else { /* 'common' yield */ | 388 | else { /* 'common' yield */ |
393 | G(L)->nCcalls--; /* finish 'luaD_call' */ | 389 | G(L)->nCcalls--; /* finish 'luaD_call' */ |
394 | luaD_poscall(L, firstArg); /* finish 'luaD_precall' */ | 390 | luaD_poscall(L, firstArg); /* finish 'luaD_precall' */ |
@@ -399,7 +395,7 @@ static void resume (lua_State *L, void *ud) { | |||
399 | 395 | ||
400 | 396 | ||
401 | static int resume_error (lua_State *L, const char *msg) { | 397 | static int resume_error (lua_State *L, const char *msg) { |
402 | L->top = L->ci->base; | 398 | L->top = L->ci->func + 1; |
403 | setsvalue2s(L, L->top, luaS_new(L, msg)); | 399 | setsvalue2s(L, L->top, luaS_new(L, msg)); |
404 | incr_top(L); | 400 | incr_top(L); |
405 | lua_unlock(L); | 401 | lua_unlock(L); |
@@ -429,7 +425,6 @@ static int recover (lua_State *L, int status) { | |||
429 | luaF_close(L, oldtop); | 425 | luaF_close(L, oldtop); |
430 | luaD_seterrorobj(L, status, oldtop); | 426 | luaD_seterrorobj(L, status, oldtop); |
431 | L->ci = ci; | 427 | L->ci = ci; |
432 | L->base = ci->base; | ||
433 | L->allowhook = ci->u.c.old_allowhook; | 428 | L->allowhook = ci->u.c.old_allowhook; |
434 | L->nny = 0; /* should be zero to be yieldable */ | 429 | L->nny = 0; /* should be zero to be yieldable */ |
435 | restore_stack_limit(L); | 430 | restore_stack_limit(L); |
@@ -477,10 +472,11 @@ LUA_API int lua_yield (lua_State *L, int nresults) { | |||
477 | lua_lock(L); | 472 | lua_lock(L); |
478 | if (L->nny > 0) | 473 | if (L->nny > 0) |
479 | luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); | 474 | luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); |
480 | L->base = L->top - nresults; /* protect stack slots below */ | ||
481 | L->status = LUA_YIELD; | 475 | L->status = LUA_YIELD; |
482 | if (!isLua(L->ci)) /* not inside a hook? */ | 476 | if (!isLua(L->ci)) { /* not inside a hook? */ |
477 | L->ci->func = L->top - nresults - 1; /* protect stack slots below ??? */ | ||
483 | luaD_throw(L, LUA_YIELD); | 478 | luaD_throw(L, LUA_YIELD); |
479 | } | ||
484 | lua_assert(L->ci->callstatus & CIST_HOOKED); /* must be inside a hook */ | 480 | lua_assert(L->ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |
485 | lua_unlock(L); | 481 | lua_unlock(L); |
486 | return 0; /* otherwise, return to 'luaD_callhook' */ | 482 | return 0; /* otherwise, return to 'luaD_callhook' */ |
@@ -501,7 +497,6 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, | |||
501 | luaF_close(L, oldtop); /* close possible pending closures */ | 497 | luaF_close(L, oldtop); /* close possible pending closures */ |
502 | luaD_seterrorobj(L, status, oldtop); | 498 | luaD_seterrorobj(L, status, oldtop); |
503 | L->ci = old_ci; | 499 | L->ci = old_ci; |
504 | L->base = old_ci->base; | ||
505 | L->allowhook = old_allowhooks; | 500 | L->allowhook = old_allowhooks; |
506 | L->nny = old_nny; | 501 | L->nny = old_nny; |
507 | restore_stack_limit(L); | 502 | restore_stack_limit(L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.53 2009/04/17 22:00:01 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.54 2009/04/28 19:04:36 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 | */ |
@@ -86,7 +86,6 @@ static void stack_init (lua_State *L1, lua_State *L) { | |||
86 | /* initialize first ci */ | 86 | /* initialize first ci */ |
87 | L1->ci->func = L1->top; | 87 | L1->ci->func = L1->top; |
88 | setnilvalue(L1->top++); /* 'function' entry for this 'ci' */ | 88 | setnilvalue(L1->top++); /* 'function' entry for this 'ci' */ |
89 | L1->base = L1->ci->base = L1->top; | ||
90 | L1->ci->top = L1->top + LUA_MINSTACK; | 89 | L1->ci->top = L1->top + LUA_MINSTACK; |
91 | L1->ci->callstatus = 0; | 90 | L1->ci->callstatus = 0; |
92 | } | 91 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.42 2009/04/17 14:28:06 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.43 2009/04/17 22:00:01 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 | */ |
@@ -77,7 +77,6 @@ typedef struct stringtable { | |||
77 | ** informations about a call | 77 | ** informations about a call |
78 | */ | 78 | */ |
79 | typedef struct CallInfo { | 79 | typedef struct CallInfo { |
80 | StkId base; /* base for this function */ | ||
81 | StkId func; /* function index in the stack */ | 80 | StkId func; /* function index in the stack */ |
82 | StkId top; /* top for this function */ | 81 | StkId top; /* top for this function */ |
83 | struct CallInfo *previous, *next; /* dynamic call link */ | 82 | struct CallInfo *previous, *next; /* dynamic call link */ |
@@ -85,6 +84,7 @@ typedef struct CallInfo { | |||
85 | lu_byte callstatus; | 84 | lu_byte callstatus; |
86 | union { | 85 | union { |
87 | struct { /* only for Lua functions */ | 86 | struct { /* only for Lua functions */ |
87 | StkId base; /* base for this function */ | ||
88 | const Instruction *savedpc; | 88 | const Instruction *savedpc; |
89 | int tailcalls; /* number of tail calls lost under this entry */ | 89 | int tailcalls; /* number of tail calls lost under this entry */ |
90 | } l; | 90 | } l; |
@@ -161,7 +161,6 @@ struct lua_State { | |||
161 | CommonHeader; | 161 | CommonHeader; |
162 | lu_byte status; | 162 | lu_byte status; |
163 | StkId top; /* first free slot in the stack */ | 163 | StkId top; /* first free slot in the stack */ |
164 | StkId base; /* base of current function */ | ||
165 | global_State *l_G; | 164 | global_State *l_G; |
166 | CallInfo *ci; /* call info for current function */ | 165 | CallInfo *ci; /* call info for current function */ |
167 | int nci; /* number of total CallInfo structures linked */ | 166 | int nci; /* number of total CallInfo structures linked */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.61 2009/04/17 14:28:06 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.62 2009/04/17 22:00:01 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 | */ |
@@ -43,7 +43,7 @@ void *l_Trick = 0; | |||
43 | int islocked = 0; | 43 | int islocked = 0; |
44 | 44 | ||
45 | 45 | ||
46 | #define obj_at(L,k) (L->ci->base+(k) - 1) | 46 | #define obj_at(L,k) (L->ci->func + (k)) |
47 | 47 | ||
48 | 48 | ||
49 | static void setnameval (lua_State *L, const char *name, int val) { | 49 | static void setnameval (lua_State *L, const char *name, int val) { |
@@ -514,7 +514,7 @@ static int mem_query (lua_State *L) { | |||
514 | 514 | ||
515 | 515 | ||
516 | static int settrick (lua_State *L) { | 516 | static int settrick (lua_State *L) { |
517 | l_Trick = (L->base)->value.gc; | 517 | l_Trick = obj_at(L, 1)->value.gc; |
518 | return 0; | 518 | return 0; |
519 | } | 519 | } |
520 | 520 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.88 2009/05/22 15:19:54 roberto Exp $ | 2 | ** $Id: lvm.c,v 2.89 2009/05/27 17:11:27 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 | */ |
@@ -357,12 +357,13 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, | |||
357 | */ | 357 | */ |
358 | void luaV_finishOp (lua_State *L) { | 358 | void luaV_finishOp (lua_State *L) { |
359 | CallInfo *ci = L->ci; | 359 | CallInfo *ci = L->ci; |
360 | StkId base = ci->u.l.base; | ||
360 | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ | 361 | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ |
361 | switch (GET_OPCODE(inst)) { /* finish its execution */ | 362 | switch (GET_OPCODE(inst)) { /* finish its execution */ |
362 | case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: | 363 | case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: |
363 | case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN: | 364 | case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN: |
364 | case OP_GETGLOBAL: case OP_GETTABLE: case OP_SELF: { | 365 | case OP_GETGLOBAL: case OP_GETTABLE: case OP_SELF: { |
365 | setobjs2s(L, ci->base + GETARG_A(inst), --L->top); | 366 | setobjs2s(L, base + GETARG_A(inst), --L->top); |
366 | break; | 367 | break; |
367 | } | 368 | } |
368 | case OP_LE: case OP_LT: case OP_EQ: { | 369 | case OP_LE: case OP_LT: case OP_EQ: { |
@@ -371,7 +372,7 @@ void luaV_finishOp (lua_State *L) { | |||
371 | /* metamethod should not be called when operand is K */ | 372 | /* metamethod should not be called when operand is K */ |
372 | lua_assert(!ISK(GETARG_B(inst))); | 373 | lua_assert(!ISK(GETARG_B(inst))); |
373 | if (GET_OPCODE(inst) == OP_LE && /* "<=" using "<" instead? */ | 374 | if (GET_OPCODE(inst) == OP_LE && /* "<=" using "<" instead? */ |
374 | ttisnil(luaT_gettmbyobj(L, ci->base + GETARG_B(inst), TM_LE))) | 375 | ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE))) |
375 | res = !res; /* invert result */ | 376 | res = !res; /* invert result */ |
376 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); | 377 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); |
377 | if (res != GETARG_A(inst)) /* condition failed? */ | 378 | if (res != GETARG_A(inst)) /* condition failed? */ |
@@ -381,14 +382,14 @@ void luaV_finishOp (lua_State *L) { | |||
381 | case OP_CONCAT: { | 382 | case OP_CONCAT: { |
382 | StkId top = L->top - 1; /* top when 'call_binTM' was called */ | 383 | StkId top = L->top - 1; /* top when 'call_binTM' was called */ |
383 | int b = GETARG_B(inst); /* first element to concatenate */ | 384 | int b = GETARG_B(inst); /* first element to concatenate */ |
384 | int total = top - 1 - (ci->base + b); /* elements yet to concatenate */ | 385 | int total = top - 1 - (base + b); /* elements yet to concatenate */ |
385 | setobj2s(L, top - 2, top); /* put TM result in proper position */ | 386 | setobj2s(L, top - 2, top); /* put TM result in proper position */ |
386 | if (total > 1) { /* are there elements to concat? */ | 387 | if (total > 1) { /* are there elements to concat? */ |
387 | L->top = top - 1; /* top is one after last element (at top-2) */ | 388 | L->top = top - 1; /* top is one after last element (at top-2) */ |
388 | luaV_concat(L, total); /* concat them (may yield again) */ | 389 | luaV_concat(L, total); /* concat them (may yield again) */ |
389 | } | 390 | } |
390 | /* move final result to final position */ | 391 | /* move final result to final position */ |
391 | setobj2s(L, ci->base + GETARG_A(inst), L->top - 1); | 392 | setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1); |
392 | L->top = ci->top; /* restore top */ | 393 | L->top = ci->top; /* restore top */ |
393 | break; | 394 | break; |
394 | } | 395 | } |
@@ -428,7 +429,7 @@ void luaV_finishOp (lua_State *L) { | |||
428 | #define dojump(i) { ci->u.l.savedpc += (i); luai_threadyield(L);} | 429 | #define dojump(i) { ci->u.l.savedpc += (i); luai_threadyield(L);} |
429 | 430 | ||
430 | 431 | ||
431 | #define Protect(x) { {x;}; base = ci->base; } | 432 | #define Protect(x) { {x;}; base = ci->u.l.base; } |
432 | 433 | ||
433 | 434 | ||
434 | #define arith_op(op,tm) { \ | 435 | #define arith_op(op,tm) { \ |
@@ -448,7 +449,7 @@ void luaV_execute (lua_State *L) { | |||
448 | CallInfo *ci = L->ci; | 449 | CallInfo *ci = L->ci; |
449 | LClosure *cl = &clvalue(ci->func)->l; | 450 | LClosure *cl = &clvalue(ci->func)->l; |
450 | TValue *k = cl->p->k; | 451 | TValue *k = cl->p->k; |
451 | StkId base = ci->base; | 452 | StkId base = ci->u.l.base; |
452 | lua_assert(isLua(ci)); | 453 | lua_assert(isLua(ci)); |
453 | /* main loop of interpreter */ | 454 | /* main loop of interpreter */ |
454 | for (;;) { | 455 | for (;;) { |
@@ -461,11 +462,11 @@ void luaV_execute (lua_State *L) { | |||
461 | ci->u.l.savedpc--; /* undo increment */ | 462 | ci->u.l.savedpc--; /* undo increment */ |
462 | luaD_throw(L, LUA_YIELD); | 463 | luaD_throw(L, LUA_YIELD); |
463 | } | 464 | } |
464 | base = ci->base; | 465 | base = ci->u.l.base; |
465 | } | 466 | } |
466 | /* warning!! several calls may realloc the stack and invalidate `ra' */ | 467 | /* warning!! several calls may realloc the stack and invalidate `ra' */ |
467 | ra = RA(i); | 468 | ra = RA(i); |
468 | lua_assert(base == ci->base && base == L->base); | 469 | lua_assert(base == ci->u.l.base); |
469 | lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); | 470 | lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); |
470 | switch (GET_OPCODE(i)) { | 471 | switch (GET_OPCODE(i)) { |
471 | case OP_MOVE: { | 472 | case OP_MOVE: { |
@@ -642,7 +643,7 @@ void luaV_execute (lua_State *L) { | |||
642 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ | 643 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
643 | if (luaD_precall(L, ra, nresults)) { /* C function? */ | 644 | if (luaD_precall(L, ra, nresults)) { /* C function? */ |
644 | if (nresults >= 0) L->top = ci->top; /* adjust results */ | 645 | if (nresults >= 0) L->top = ci->top; /* adjust results */ |
645 | base = ci->base; | 646 | base = ci->u.l.base; |
646 | continue; | 647 | continue; |
647 | } | 648 | } |
648 | else { /* Lua function */ | 649 | else { /* Lua function */ |
@@ -656,7 +657,7 @@ void luaV_execute (lua_State *L) { | |||
656 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ | 657 | if (b != 0) L->top = ra+b; /* else previous instruction set top */ |
657 | lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); | 658 | lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); |
658 | if (luaD_precall(L, ra, LUA_MULTRET)) { /* C function? */ | 659 | if (luaD_precall(L, ra, LUA_MULTRET)) { /* C function? */ |
659 | base = ci->base; | 660 | base = ci->u.l.base; |
660 | continue; | 661 | continue; |
661 | } | 662 | } |
662 | else { | 663 | else { |
@@ -666,12 +667,12 @@ void luaV_execute (lua_State *L) { | |||
666 | StkId nfunc = nci->func; /* called function index */ | 667 | StkId nfunc = nci->func; /* called function index */ |
667 | StkId ofunc = oci->func; | 668 | StkId ofunc = oci->func; |
668 | int aux; | 669 | int aux; |
669 | if (cl->p->sizep > 0) luaF_close(L, oci->base); | 670 | if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base); |
670 | L->base = oci->base = ofunc + (nci->base - nfunc); | 671 | oci->u.l.base = ofunc + (nci->u.l.base - nfunc); |
671 | for (aux = 0; nfunc+aux < L->top; aux++) /* move frame down */ | 672 | for (aux = 0; nfunc+aux < L->top; aux++) /* move frame down */ |
672 | setobjs2s(L, ofunc + aux, nfunc + aux); | 673 | setobjs2s(L, ofunc + aux, nfunc + aux); |
673 | oci->top = L->top = ofunc + aux; /* correct top */ | 674 | oci->top = L->top = ofunc + aux; /* correct top */ |
674 | lua_assert(L->top == oci->base + clvalue(ofunc)->l.p->maxstacksize); | 675 | lua_assert(L->top == oci->u.l.base + clvalue(ofunc)->l.p->maxstacksize); |
675 | oci->u.l.savedpc = nci->u.l.savedpc; | 676 | oci->u.l.savedpc = nci->u.l.savedpc; |
676 | oci->u.l.tailcalls++; /* one more call lost */ | 677 | oci->u.l.tailcalls++; /* one more call lost */ |
677 | ci = L->ci = oci; /* remove new frame */ | 678 | ci = L->ci = oci; /* remove new frame */ |
@@ -789,7 +790,7 @@ void luaV_execute (lua_State *L) { | |||
789 | case OP_VARARG: { | 790 | case OP_VARARG: { |
790 | int b = GETARG_B(i) - 1; | 791 | int b = GETARG_B(i) - 1; |
791 | int j; | 792 | int j; |
792 | int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; | 793 | int n = cast_int(base - ci->func) - cl->p->numparams - 1; |
793 | if (b == LUA_MULTRET) { | 794 | if (b == LUA_MULTRET) { |
794 | Protect(luaD_checkstack(L, n)); | 795 | Protect(luaD_checkstack(L, n)); |
795 | ra = RA(i); /* previous call may change the stack */ | 796 | ra = RA(i); /* previous call may change the stack */ |
@@ -798,7 +799,7 @@ void luaV_execute (lua_State *L) { | |||
798 | } | 799 | } |
799 | for (j = 0; j < b; j++) { | 800 | for (j = 0; j < b; j++) { |
800 | if (j < n) { | 801 | if (j < n) { |
801 | setobjs2s(L, ra + j, ci->base - n + j); | 802 | setobjs2s(L, ra + j, base - n + j); |
802 | } | 803 | } |
803 | else { | 804 | else { |
804 | setnilvalue(ra + j); | 805 | setnilvalue(ra + j); |
@@ -815,7 +816,7 @@ void luaV_execute (lua_State *L) { | |||
815 | lua_assert(ci == L->ci); | 816 | lua_assert(ci == L->ci); |
816 | cl = &clvalue(ci->func)->l; | 817 | cl = &clvalue(ci->func)->l; |
817 | k = cl->p->k; | 818 | k = cl->p->k; |
818 | base = ci->base; | 819 | base = ci->u.l.base; |
819 | } | 820 | } |
820 | } | 821 | } |
821 | 822 | ||