aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-15 13:34:29 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-15 13:34:29 -0200
commit0682fe816929da2e5abe8e191ad9c8509e6bfc12 (patch)
treebac8b079fde63e7f2e436e51ed6fd571dfd6f195 /lopcodes.h
parentb1379936cf35787d3ef3aab82d1607a3e1562eef (diff)
downloadlua-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.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/lopcodes.h b/lopcodes.h
index 3c7a9573..b2e22c27 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -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++ */
267OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ 267OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
268OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ 268OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */
269 269
270OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ 270OP_RETURN,/* A B C return R(A), ... ,R(A+B-2) (see note) */
271OP_RETVARARG,/* A B return R(A), ... ,R(A+B-2) (see note) */
272OP_RETURN0,/* return */ 271OP_RETURN0,/* return */
273OP_RETURN1,/* A return R(A) */ 272OP_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)