From 6a98aa0bb0426acdf4a9ef75b1d3200fd972e77d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy <roberto@inf.puc-rio.br> Date: Thu, 20 Apr 2017 16:53:55 -0300 Subject: new opcode LOADI (for loading immediate integers) --- lcode.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lcode.c') diff --git a/lcode.c b/lcode.c index aca0256d..f48221cf 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.111 2016/07/19 17:12:07 roberto Exp roberto $ +** $Id: lcode.c,v 2.112 2016/12/22 13:08:50 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -343,7 +343,7 @@ static int codeextraarg (FuncState *fs, int a) { ** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX' ** instruction with "extra argument". */ -int luaK_codek (FuncState *fs, int reg, int k) { +static int luaK_codek (FuncState *fs, int reg, int k) { if (k <= MAXARG_Bx) return luaK_codeABx(fs, OP_LOADK, reg, k); else { @@ -468,7 +468,7 @@ int luaK_stringK (FuncState *fs, TString *s) { ** same value; conversion to 'void*' is used only for hashing, so there ** are no "precision" problems. */ -int luaK_intK (FuncState *fs, lua_Integer n) { +static int luaK_intK (FuncState *fs, lua_Integer n) { TValue k, o; setpvalue(&k, cast(void*, cast(size_t, n))); setivalue(&o, n); @@ -507,6 +507,14 @@ static int nilK (FuncState *fs) { } +void luaK_int (FuncState *fs, int reg, lua_Integer i) { + if (-MAXARG_sBx <= i && i <= MAXARG_sBx) + luaK_codeAsBx(fs, OP_LOADI, reg, cast_int(i)); + else + luaK_codek(fs, reg, luaK_intK(fs, i)); +} + + /* ** Fix an expression to return the number of results 'nresults'. ** Either 'e' is a multi-ret expression (function call or vararg) @@ -612,7 +620,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { break; } case VKINT: { - luaK_codek(fs, reg, luaK_intK(fs, e->u.ival)); + luaK_int(fs, reg, e->u.ival); break; } case VRELOCABLE: { -- cgit v1.2.3-55-g6feb