summaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-09-19 15:38:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-09-19 15:38:14 -0300
commitabb17cf19bf7328a394f1758542172c4b4dbb539 (patch)
tree2dce52a3922e5772aca093b53442e7220d24634f /lcode.c
parente0c0e2ee14f519ad33429533f87519753f07051a (diff)
downloadlua-github-abb17cf19bf7328a394f1758542172c4b4dbb539.tar.gz
new opcode OP_LOADF (load immediate float)
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/lcode.c b/lcode.c
index 1edf08aa..f7bc2140 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.c,v 2.121 2017/06/29 15:06:44 roberto Exp roberto $
+** $Id: lcode.c,v 2.122 2017/09/13 19:50:08 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -579,6 +579,18 @@ void luaK_int (FuncState *fs, int reg, lua_Integer i) {
}
+static void luaK_float (FuncState *fs, int reg, lua_Number f) {
+ TValue v;
+ lua_Integer fi;
+ setfltvalue(&v, f);
+ if (luaV_tointeger(&v, &fi, 0) &&
+ l_castS2U(fi) + MAXARG_sBx <= l_castS2U(MAXARG_Bx))
+ luaK_codeAsBx(fs, OP_LOADF, reg, cast_int(fi));
+ else
+ luaK_codek(fs, reg, luaK_numberK(fs, f));
+}
+
+
/*
** Fix an expression to return the number of results 'nresults'.
** Either 'e' is a multi-ret expression (function call or vararg)
@@ -688,7 +700,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
break;
}
case VKFLT: {
- luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval));
+ luaK_float(fs, reg, e->u.nval);
break;
}
case VKINT: {