diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-15 13:34:29 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-15 13:34:29 -0200 |
commit | 0682fe816929da2e5abe8e191ad9c8509e6bfc12 (patch) | |
tree | bac8b079fde63e7f2e436e51ed6fd571dfd6f195 /lopcodes.h | |
parent | b1379936cf35787d3ef3aab82d1607a3e1562eef (diff) | |
download | lua-0682fe816929da2e5abe8e191ad9c8509e6bfc12.tar.gz lua-0682fe816929da2e5abe8e191ad9c8509e6bfc12.tar.bz2 lua-0682fe816929da2e5abe8e191ad9c8509e6bfc12.zip |
some simplifications/optimizations in returns from Lua functions
Diffstat (limited to 'lopcodes.h')
-rw-r--r-- | lopcodes.h | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.186 2018/02/07 15:18:04 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.187 2018/02/09 15:16:06 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -267,8 +267,7 @@ OP_TESTSET,/* A B if (not R(B) == k) then R(A) := R(B) else pc++ */ | |||
267 | OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ | 267 | OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ |
268 | OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ | 268 | OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ |
269 | 269 | ||
270 | OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ | 270 | OP_RETURN,/* A B C return R(A), ... ,R(A+B-2) (see note) */ |
271 | OP_RETVARARG,/* A B return R(A), ... ,R(A+B-2) (see note) */ | ||
272 | OP_RETURN0,/* return */ | 271 | OP_RETURN0,/* return */ |
273 | OP_RETURN1,/* A return R(A) */ | 272 | OP_RETURN1,/* A return R(A) */ |
274 | 273 | ||
@@ -302,14 +301,13 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
302 | /*=========================================================================== | 301 | /*=========================================================================== |
303 | Notes: | 302 | Notes: |
304 | (*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then 'top' is | 303 | (*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then 'top' is |
305 | set to last_result+1, so next open instruction (OP_CALL, OP_RETURN, | 304 | set to last_result+1, so next open instruction (OP_CALL, OP_RETURN*, |
306 | OP_SETLIST) may use 'top'. | 305 | OP_SETLIST) may use 'top'. |
307 | 306 | ||
308 | (*) In OP_VARARG, if (C == 0) then use actual number of varargs and | 307 | (*) In OP_VARARG, if (C == 0) then use actual number of varargs and |
309 | set top (like in OP_CALL with C == 0). | 308 | set top (like in OP_CALL with C == 0). |
310 | 309 | ||
311 | (*) In OP_RETURN/OP_RETVARARG, if (B == 0) then return up to 'top'. | 310 | (*) In OP_RETURN, if (B == 0) then return up to 'top'. |
312 | (OP_RETVARARG is the return instruction for vararg functions.) | ||
313 | 311 | ||
314 | (*) In OP_SETLIST, if (B == 0) then real B = 'top'; if (C == 0) then | 312 | (*) In OP_SETLIST, if (B == 0) then real B = 'top'; if (C == 0) then |
315 | next 'instruction' is EXTRAARG(real C). | 313 | next 'instruction' is EXTRAARG(real C). |
@@ -326,9 +324,11 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
326 | 324 | ||
327 | (*) All 'skips' (pc++) assume that next instruction is a jump. | 325 | (*) All 'skips' (pc++) assume that next instruction is a jump. |
328 | 326 | ||
329 | (*) In instructions ending a function (OP_RETURN*, OP_TAILCALL), k | 327 | (*) In instructions OP_RETURN/OP_TAILCALL, 'k' specifies that the |
330 | specifies that the function builds upvalues, which may need to be | 328 | function either builds upvalues, which may need to be closed, or is |
331 | closed. | 329 | vararg, which must be corrected before returning. When 'k' is true, |
330 | C > 0 means the function is vararg and (C - 1) is its number of | ||
331 | fixed parameters. | ||
332 | 332 | ||
333 | ===========================================================================*/ | 333 | ===========================================================================*/ |
334 | 334 | ||
@@ -351,7 +351,9 @@ LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES]; | |||
351 | #define testOTMode(m) (luaP_opmodes[m] & (1 << 6)) | 351 | #define testOTMode(m) (luaP_opmodes[m] & (1 << 6)) |
352 | 352 | ||
353 | /* "out top" (set top for next instruction) */ | 353 | /* "out top" (set top for next instruction) */ |
354 | #define isOT(i) (testOTMode(GET_OPCODE(i)) && GETARG_C(i) == 0) | 354 | #define isOT(i) \ |
355 | ((testOTMode(GET_OPCODE(i)) && GETARG_C(i) == 0) || \ | ||
356 | GET_OPCODE(i) == OP_TAILCALL) | ||
355 | 357 | ||
356 | /* "in top" (uses top from previous instruction) */ | 358 | /* "in top" (uses top from previous instruction) */ |
357 | #define isIT(i) (testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0) | 359 | #define isIT(i) (testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0) |