diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-09-19 15:38:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-09-19 15:38:14 -0300 |
commit | abb17cf19bf7328a394f1758542172c4b4dbb539 (patch) | |
tree | 2dce52a3922e5772aca093b53442e7220d24634f /lcode.c | |
parent | e0c0e2ee14f519ad33429533f87519753f07051a (diff) | |
download | lua-abb17cf19bf7328a394f1758542172c4b4dbb539.tar.gz lua-abb17cf19bf7328a394f1758542172c4b4dbb539.tar.bz2 lua-abb17cf19bf7328a394f1758542172c4b4dbb539.zip |
new opcode OP_LOADF (load immediate float)
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 16 |
1 files changed, 14 insertions, 2 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: { |