aboutsummaryrefslogtreecommitdiff
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
parente0c0e2ee14f519ad33429533f87519753f07051a (diff)
downloadlua-abb17cf19bf7328a394f1758542172c4b4dbb539.tar.gz
lua-abb17cf19bf7328a394f1758542172c4b4dbb539.tar.bz2
lua-abb17cf19bf7328a394f1758542172c4b4dbb539.zip
new opcode OP_LOADF (load immediate float)
-rw-r--r--lcode.c16
-rw-r--r--lopcodes.c4
-rw-r--r--lopcodes.h3
-rw-r--r--lvm.c7
4 files changed, 25 insertions, 5 deletions
diff --git a/lcode.c b/lcode.c
index 1edf08aa..f7bc2140 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.121 2017/06/29 15:06:44 roberto Exp roberto $ 2** $Id: lcode.c,v 2.122 2017/09/13 19:50:08 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -579,6 +579,18 @@ void luaK_int (FuncState *fs, int reg, lua_Integer i) {
579} 579}
580 580
581 581
582static void luaK_float (FuncState *fs, int reg, lua_Number f) {
583 TValue v;
584 lua_Integer fi;
585 setfltvalue(&v, f);
586 if (luaV_tointeger(&v, &fi, 0) &&
587 l_castS2U(fi) + MAXARG_sBx <= l_castS2U(MAXARG_Bx))
588 luaK_codeAsBx(fs, OP_LOADF, reg, cast_int(fi));
589 else
590 luaK_codek(fs, reg, luaK_numberK(fs, f));
591}
592
593
582/* 594/*
583** Fix an expression to return the number of results 'nresults'. 595** Fix an expression to return the number of results 'nresults'.
584** Either 'e' is a multi-ret expression (function call or vararg) 596** Either 'e' is a multi-ret expression (function call or vararg)
@@ -688,7 +700,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
688 break; 700 break;
689 } 701 }
690 case VKFLT: { 702 case VKFLT: {
691 luaK_codek(fs, reg, luaK_numberK(fs, e->u.nval)); 703 luaK_float(fs, reg, e->u.nval);
692 break; 704 break;
693 } 705 }
694 case VKINT: { 706 case VKINT: {
diff --git a/lopcodes.c b/lopcodes.c
index 7e1ace25..9279a8df 100644
--- a/lopcodes.c
+++ b/lopcodes.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.c,v 1.61 2017/09/13 19:50:08 roberto Exp roberto $ 2** $Id: lopcodes.c,v 1.62 2017/09/15 14:19: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*/
@@ -20,6 +20,7 @@
20LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { 20LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
21 "MOVE", 21 "MOVE",
22 "LOADI", 22 "LOADI",
23 "LOADF",
23 "LOADK", 24 "LOADK",
24 "LOADKX", 25 "LOADKX",
25 "LOADBOOL", 26 "LOADBOOL",
@@ -82,6 +83,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
82/* T A B C mode opcode */ 83/* T A B C mode opcode */
83 opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 84 opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */
84 ,opmode(0, 1, OpArgU, OpArgN, iAsBx) /* OP_LOADI */ 85 ,opmode(0, 1, OpArgU, OpArgN, iAsBx) /* OP_LOADI */
86 ,opmode(0, 1, OpArgU, OpArgN, iAsBx) /* OP_LOADF */
85 ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 87 ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
86 ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ 88 ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */
87 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 89 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
diff --git a/lopcodes.h b/lopcodes.h
index 3d69196c..9e0ce498 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.158 2017/09/15 14:19:06 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.159 2017/09/18 16:07:54 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*/
@@ -175,6 +175,7 @@ name args description
175------------------------------------------------------------------------*/ 175------------------------------------------------------------------------*/
176OP_MOVE,/* A B R(A) := R(B) */ 176OP_MOVE,/* A B R(A) := R(B) */
177OP_LOADI,/* A sBx R(A) := sBx */ 177OP_LOADI,/* A sBx R(A) := sBx */
178OP_LOADF,/* A sBx R(A) := (lua_Number)sBx */
178OP_LOADK,/* A Bx R(A) := Kst(Bx) */ 179OP_LOADK,/* A Bx R(A) := Kst(Bx) */
179OP_LOADKX,/* A R(A) := Kst(extra arg) */ 180OP_LOADKX,/* A R(A) := Kst(extra arg) */
180OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ 181OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */
diff --git a/lvm.c b/lvm.c
index b1e74f3d..a41b44d6 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.291 2017/08/14 18:33:14 roberto Exp roberto $ 2** $Id: lvm.c,v 2.292 2017/09/13 19:50:08 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -829,6 +829,11 @@ void luaV_execute (lua_State *L) {
829 setivalue(s2v(ra), b); 829 setivalue(s2v(ra), b);
830 vmbreak; 830 vmbreak;
831 } 831 }
832 vmcase(OP_LOADF) {
833 int b = GETARG_sBx(i);
834 setfltvalue(s2v(ra), cast_num(b));
835 vmbreak;
836 }
832 vmcase(OP_LOADKX) { 837 vmcase(OP_LOADKX) {
833 TValue *rb; 838 TValue *rb;
834 lua_assert(GET_OPCODE(*pc) == OP_EXTRAARG); 839 lua_assert(GET_OPCODE(*pc) == OP_EXTRAARG);