diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-28 13:42:57 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-28 13:42:57 -0200 |
| commit | cf7eff45f3abf2386d5392c0b431498bbb274ac7 (patch) | |
| tree | 0eaafe3456bd03b241e447f1375296341fb648e8 /ltm.c | |
| parent | 8691612f01ae4b32d861464032521d969766c1c5 (diff) | |
| download | lua-cf7eff45f3abf2386d5392c0b431498bbb274ac7.tar.gz lua-cf7eff45f3abf2386d5392c0b431498bbb274ac7.tar.bz2 lua-cf7eff45f3abf2386d5392c0b431498bbb274ac7.zip | |
keep control of stack top in Lua functions concentrated in 'luaV_execute'
Diffstat (limited to 'ltm.c')
| -rw-r--r-- | ltm.c | 22 |
1 files changed, 5 insertions, 17 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 2.54 2017/12/19 16:40:17 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.55 2017/12/20 14:58:05 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -101,7 +101,7 @@ const char *luaT_objtypename (lua_State *L, const TValue *o) { | |||
| 101 | 101 | ||
| 102 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, | 102 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, |
| 103 | const TValue *p2, const TValue *p3) { | 103 | const TValue *p2, const TValue *p3) { |
| 104 | StkId func = (isLuacode(L->ci)) ? L->ci->top : L->top; | 104 | StkId func = L->top; |
| 105 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ | 105 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ |
| 106 | setobj2s(L, func + 1, p1); /* 1st argument */ | 106 | setobj2s(L, func + 1, p1); /* 1st argument */ |
| 107 | setobj2s(L, func + 2, p2); /* 2nd argument */ | 107 | setobj2s(L, func + 2, p2); /* 2nd argument */ |
| @@ -115,8 +115,8 @@ void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, | |||
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | 117 | ||
| 118 | static void reallycallTMres (lua_State *L, const TValue *f, const TValue *p1, | 118 | void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, |
| 119 | const TValue *p2, StkId res) { | 119 | const TValue *p2, StkId res) { |
| 120 | ptrdiff_t result = savestack(L, res); | 120 | ptrdiff_t result = savestack(L, res); |
| 121 | StkId func = L->top; | 121 | StkId func = L->top; |
| 122 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ | 122 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ |
| @@ -133,29 +133,19 @@ static void reallycallTMres (lua_State *L, const TValue *f, const TValue *p1, | |||
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | 135 | ||
| 136 | void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, | ||
| 137 | const TValue *p2, StkId res) { | ||
| 138 | if (isLuacode(L->ci)) | ||
| 139 | L->top = L->ci->top; /* prepare top */ | ||
| 140 | reallycallTMres(L, f, p1, p2, res); | ||
| 141 | } | ||
| 142 | |||
| 143 | |||
| 144 | static int callbinTM (lua_State *L, const TValue *p1, const TValue *p2, | 136 | static int callbinTM (lua_State *L, const TValue *p1, const TValue *p2, |
| 145 | StkId res, TMS event) { | 137 | StkId res, TMS event) { |
| 146 | const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ | 138 | const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ |
| 147 | if (ttisnil(tm)) | 139 | if (ttisnil(tm)) |
| 148 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ | 140 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ |
| 149 | if (ttisnil(tm)) return 0; | 141 | if (ttisnil(tm)) return 0; |
| 150 | reallycallTMres(L, tm, p1, p2, res); | 142 | luaT_callTMres(L, tm, p1, p2, res); |
| 151 | return 1; | 143 | return 1; |
| 152 | } | 144 | } |
| 153 | 145 | ||
| 154 | 146 | ||
| 155 | void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, | 147 | void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, |
| 156 | StkId res, TMS event) { | 148 | StkId res, TMS event) { |
| 157 | if (event != TM_CONCAT && isLuacode(L->ci)) | ||
| 158 | L->top = L->ci->top; /* prepare top */ | ||
| 159 | if (!callbinTM(L, p1, p2, res, event)) { | 149 | if (!callbinTM(L, p1, p2, res, event)) { |
| 160 | switch (event) { | 150 | switch (event) { |
| 161 | case TM_CONCAT: | 151 | case TM_CONCAT: |
| @@ -195,8 +185,6 @@ void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2, | |||
| 195 | 185 | ||
| 196 | int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, | 186 | int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, |
| 197 | TMS event) { | 187 | TMS event) { |
| 198 | if (isLuacode(L->ci)) | ||
| 199 | L->top = L->ci->top; /* prepare top */ | ||
| 200 | if (callbinTM(L, p1, p2, L->top, event)) /* try original event */ | 188 | if (callbinTM(L, p1, p2, L->top, event)) /* try original event */ |
| 201 | return !l_isfalse(s2v(L->top)); | 189 | return !l_isfalse(s2v(L->top)); |
| 202 | else if (event == TM_LE) { | 190 | else if (event == TM_LE) { |
