diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-09 13:16:06 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-09 13:16:06 -0200 |
| commit | b1379936cf35787d3ef3aab82d1607a3e1562eef (patch) | |
| tree | fe47cb5c35fddab945faf731f0bc175bf5431352 /lcode.c | |
| parent | 4e0de3a43cc30a83334c272cb7575bf8412bfeae (diff) | |
| download | lua-b1379936cf35787d3ef3aab82d1607a3e1562eef.tar.gz lua-b1379936cf35787d3ef3aab82d1607a3e1562eef.tar.bz2 lua-b1379936cf35787d3ef3aab82d1607a3e1562eef.zip | |
vararg back to '...' (but with another implementation)
new implementation should have zero overhead for non-vararg functions
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 26 |
1 files changed, 13 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.151 2018/01/27 16:56:33 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.152 2018/01/28 15:13:26 roberto Exp roberto $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -31,7 +31,7 @@ | |||
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | /* Maximum number of registers in a Lua function (must fit in 8 bits) */ | 33 | /* Maximum number of registers in a Lua function (must fit in 8 bits) */ |
| 34 | #define MAXREGS 255 | 34 | #define MAXREGS 254 |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | #define hasjumps(e) ((e)->t != (e)->f) | 37 | #define hasjumps(e) ((e)->t != (e)->f) |
| @@ -157,17 +157,17 @@ int luaK_jump (FuncState *fs) { | |||
| 157 | ** Code a 'return' instruction | 157 | ** Code a 'return' instruction |
| 158 | */ | 158 | */ |
| 159 | void luaK_ret (FuncState *fs, int first, int nret) { | 159 | void luaK_ret (FuncState *fs, int first, int nret) { |
| 160 | switch (nret) { | 160 | OpCode op; |
| 161 | case 0: | 161 | if (fs->f->is_vararg) |
| 162 | luaK_codeABC(fs, OP_RETURN0, 0, 0, 0); | 162 | op = OP_RETVARARG; |
| 163 | break; | 163 | else { |
| 164 | case 1: | 164 | switch (nret) { |
| 165 | luaK_codeABC(fs, OP_RETURN1, first, 0, 0); | 165 | case 0: op = OP_RETURN0; break; |
| 166 | break; | 166 | case 1: op = OP_RETURN1; break; |
| 167 | default: | 167 | default: op = OP_RETURN; break; |
| 168 | luaK_codeABC(fs, OP_RETURN, first, nret + 1, 0); | 168 | } |
| 169 | break; | ||
| 170 | } | 169 | } |
| 170 | luaK_codeABC(fs, op, first, nret + 1, fs->f->numparams); | ||
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | 173 | ||
| @@ -1647,7 +1647,7 @@ void luaK_finish (FuncState *fs) { | |||
| 1647 | lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc)); | 1647 | lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc)); |
| 1648 | switch (GET_OPCODE(*pc)) { | 1648 | switch (GET_OPCODE(*pc)) { |
| 1649 | case OP_RETURN: case OP_RETURN0: case OP_RETURN1: | 1649 | case OP_RETURN: case OP_RETURN0: case OP_RETURN1: |
| 1650 | case OP_TAILCALL: { | 1650 | case OP_RETVARARG: case OP_TAILCALL: { |
| 1651 | if (p->sizep > 0) | 1651 | if (p->sizep > 0) |
| 1652 | SETARG_k(*pc, 1); /* signal that they must close upvalues */ | 1652 | SETARG_k(*pc, 1); /* signal that they must close upvalues */ |
| 1653 | break; | 1653 | break; |
