From ab07005568a399f2e97996677472d9e6e69c9f4f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 18 Dec 2017 13:44:44 -0200 Subject: [PATCH] new auxiliary function 'luaK_isKint' + removal of 'luaK_needclose', which was not being used anywhere. --- lcode.c | 26 ++++++++++---------------- lcode.h | 4 ++-- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lcode.c b/lcode.c index 162b732d..04b534e2 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.144 2017/12/14 14:24:02 roberto Exp roberto $ +** $Id: lcode.c,v 2.145 2017/12/15 18:53:48 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -259,18 +259,6 @@ void luaK_patchtohere (FuncState *fs, int list) { } -/* -** Check whether some jump in given list needs a close instruction. -*/ -int luaK_needclose (FuncState *fs, int list) { - for (; list != NO_JUMP; list = getjump(fs, list)) { - if (GETARG_A(fs->f->code[list])) /* needs close? */ - return 1; - } - return 0; -} - - /* ** Correct a jump list to jump to 'target'. If 'hasclose' is true, ** 'target' contains an OP_CLOSE instruction (see first assert). @@ -1090,14 +1078,20 @@ static int isKstr (FuncState *fs, expdesc *e) { ttisshrstring(&fs->f->k[e->u.info])); } +/* +** Check whether expression 'e' is a literal integer. +*/ +int luaK_isKint (expdesc *e) { + return (e->k == VKINT && !hasjumps(e)); +} + /* ** Check whether expression 'e' is a literal integer in ** proper range to fit in register C */ static int isCint (expdesc *e) { - return (e->k == VKINT && !hasjumps(e) && - l_castS2U(e->u.ival) <= l_castS2U(MAXARG_C)); + return luaK_isKint(e) && (l_castS2U(e->u.ival) <= l_castS2U(MAXARG_C)); } @@ -1106,7 +1100,7 @@ static int isCint (expdesc *e) { ** proper range to fit in register sC */ static int isSCint (expdesc *e) { - return (e->k == VKINT && !hasjumps(e) && fitsC(e->u.ival)); + return luaK_isKint(e) && fitsC(e->u.ival); } diff --git a/lcode.h b/lcode.h index a1fd735d..beeba54f 100644 --- a/lcode.h +++ b/lcode.h @@ -1,5 +1,5 @@ /* -** $Id: lcode.h,v 1.68 2017/10/04 21:56:32 roberto Exp roberto $ +** $Id: lcode.h,v 1.69 2017/11/30 13:29:18 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -55,6 +55,7 @@ LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); LUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx); LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A, int B, int C, int k); +LUAI_FUNC int luaK_isKint (expdesc *e); LUAI_FUNC void luaK_fixline (FuncState *fs, int line); LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); @@ -80,7 +81,6 @@ LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); void luaK_patchgoto (FuncState *fs, int list, int target, int hasclose); LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); LUAI_FUNC void luaK_patchclose (FuncState *fs, int list); -LUAI_FUNC int luaK_needclose (FuncState *fs, int list); LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); LUAI_FUNC int luaK_getlabel (FuncState *fs); LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);