diff options
| -rw-r--r-- | lcode.c | 16 | ||||
| -rw-r--r-- | lopcodes.c | 4 | ||||
| -rw-r--r-- | lopcodes.h | 3 | ||||
| -rw-r--r-- | lvm.c | 7 |
4 files changed, 25 insertions, 5 deletions
| @@ -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 | ||
| 582 | static 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: { |
| @@ -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 @@ | |||
| 20 | LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { | 20 | LUAI_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 */ |
| @@ -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 | ------------------------------------------------------------------------*/ |
| 176 | OP_MOVE,/* A B R(A) := R(B) */ | 176 | OP_MOVE,/* A B R(A) := R(B) */ |
| 177 | OP_LOADI,/* A sBx R(A) := sBx */ | 177 | OP_LOADI,/* A sBx R(A) := sBx */ |
| 178 | OP_LOADF,/* A sBx R(A) := (lua_Number)sBx */ | ||
| 178 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ | 179 | OP_LOADK,/* A Bx R(A) := Kst(Bx) */ |
| 179 | OP_LOADKX,/* A R(A) := Kst(extra arg) */ | 180 | OP_LOADKX,/* A R(A) := Kst(extra arg) */ |
| 180 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ | 181 | OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ |
| @@ -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); |
