mirror of
https://github.com/lua/lua
synced 2024-11-25 14:20:41 +03:00
new opcode OP_LOADF (load immediate float)
This commit is contained in:
parent
e0c0e2ee14
commit
abb17cf19b
16
lcode.c
16
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: {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lopcodes.c,v 1.61 2017/09/13 19:50:08 roberto Exp roberto $
|
||||
** $Id: lopcodes.c,v 1.62 2017/09/15 14:19:06 roberto Exp roberto $
|
||||
** Opcodes for Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -20,6 +20,7 @@
|
||||
LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
|
||||
"MOVE",
|
||||
"LOADI",
|
||||
"LOADF",
|
||||
"LOADK",
|
||||
"LOADKX",
|
||||
"LOADBOOL",
|
||||
@ -82,6 +83,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
|
||||
/* T A B C mode opcode */
|
||||
opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */
|
||||
,opmode(0, 1, OpArgU, OpArgN, iAsBx) /* OP_LOADI */
|
||||
,opmode(0, 1, OpArgU, OpArgN, iAsBx) /* OP_LOADF */
|
||||
,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
|
||||
,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */
|
||||
,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lopcodes.h,v 1.158 2017/09/15 14:19:06 roberto Exp roberto $
|
||||
** $Id: lopcodes.h,v 1.159 2017/09/18 16:07:54 roberto Exp roberto $
|
||||
** Opcodes for Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -175,6 +175,7 @@ name args description
|
||||
------------------------------------------------------------------------*/
|
||||
OP_MOVE,/* A B R(A) := R(B) */
|
||||
OP_LOADI,/* A sBx R(A) := sBx */
|
||||
OP_LOADF,/* A sBx R(A) := (lua_Number)sBx */
|
||||
OP_LOADK,/* A Bx R(A) := Kst(Bx) */
|
||||
OP_LOADKX,/* A R(A) := Kst(extra arg) */
|
||||
OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */
|
||||
|
7
lvm.c
7
lvm.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.c,v 2.291 2017/08/14 18:33:14 roberto Exp roberto $
|
||||
** $Id: lvm.c,v 2.292 2017/09/13 19:50:08 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -829,6 +829,11 @@ void luaV_execute (lua_State *L) {
|
||||
setivalue(s2v(ra), b);
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_LOADF) {
|
||||
int b = GETARG_sBx(i);
|
||||
setfltvalue(s2v(ra), cast_num(b));
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_LOADKX) {
|
||||
TValue *rb;
|
||||
lua_assert(GET_OPCODE(*pc) == OP_EXTRAARG);
|
||||
|
Loading…
Reference in New Issue
Block a user