diff options
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.163 2002/03/11 12:45:00 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.164 2002/03/15 17:17:16 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 | */ |
@@ -101,22 +101,24 @@ void luaD_growstack (lua_State *L, int n) { | |||
101 | ** Open a hole inside the stack at `pos' | 101 | ** Open a hole inside the stack at `pos' |
102 | */ | 102 | */ |
103 | static void luaD_openstack (lua_State *L, StkId pos) { | 103 | static void luaD_openstack (lua_State *L, StkId pos) { |
104 | int i = L->top-pos; | 104 | StkId p; |
105 | while (i--) setobj(pos+i+1, pos+i); | 105 | for (p = L->top; p > pos; p--) setobj(p, p-1); |
106 | incr_top(L); | 106 | incr_top(L); |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { | 110 | static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { |
111 | L->ci->top = L->top; | 111 | ptrdiff_t top = savestack(L, L->top); |
112 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 112 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
113 | L->ci->top += LUA_MINSTACK; | ||
113 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 114 | L->allowhooks = 0; /* cannot call hooks inside a hook */ |
114 | lua_unlock(L); | 115 | lua_unlock(L); |
115 | (*hook)(L, ar); | 116 | (*hook)(L, ar); |
116 | lua_lock(L); | 117 | lua_lock(L); |
117 | lua_assert(L->allowhooks == 0); | 118 | lua_assert(L->allowhooks == 0); |
118 | L->allowhooks = 1; | 119 | L->allowhooks = 1; |
119 | L->top = L->ci->top; | 120 | L->ci->top -= LUA_MINSTACK; |
121 | L->top = restorestack(L, top); | ||
120 | } | 122 | } |
121 | 123 | ||
122 | 124 | ||
@@ -218,8 +220,7 @@ StkId luaD_precall (lua_State *L, StkId func) { | |||
218 | ci->savedpc = p->code; /* starting point */ | 220 | ci->savedpc = p->code; /* starting point */ |
219 | if (p->is_vararg) /* varargs? */ | 221 | if (p->is_vararg) /* varargs? */ |
220 | adjust_varargs(L, p->numparams); | 222 | adjust_varargs(L, p->numparams); |
221 | if (ci->base > L->stack_last - p->maxstacksize) | 223 | luaD_checkstack(L, p->maxstacksize); |
222 | luaD_growstack(L, p->maxstacksize); | ||
223 | ci->line = 0; | 224 | ci->line = 0; |
224 | ci->top = ci->base + p->maxstacksize; | 225 | ci->top = ci->base + p->maxstacksize; |
225 | while (L->top < ci->top) | 226 | while (L->top < ci->top) |
@@ -245,9 +246,9 @@ StkId luaD_precall (lua_State *L, StkId func) { | |||
245 | void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { | 246 | void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { |
246 | StkId res; | 247 | StkId res; |
247 | if (L->callhook) { | 248 | if (L->callhook) { |
248 | StkId stack = L->stack; /* next call may change stack */ | 249 | ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ |
249 | luaD_callHook(L, L->callhook, "return"); | 250 | luaD_callHook(L, L->callhook, "return"); |
250 | firstResult = (firstResult - stack) + L->stack; | 251 | firstResult = restorestack(L, fr); |
251 | } | 252 | } |
252 | res = L->ci->base - 1; /* func == final position of 1st result */ | 253 | res = L->ci->base - 1; /* func == final position of 1st result */ |
253 | L->ci--; | 254 | L->ci--; |