diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-04-20 16:53:55 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-04-20 16:53:55 -0300 |
| commit | 6a98aa0bb0426acdf4a9ef75b1d3200fd972e77d (patch) | |
| tree | 0cf827d0f9d328be0c3aedbb7def8bc964905415 /lcode.c | |
| parent | c354211744e80c14314b3a363e7d57f5751be835 (diff) | |
| download | lua-6a98aa0bb0426acdf4a9ef75b1d3200fd972e77d.tar.gz lua-6a98aa0bb0426acdf4a9ef75b1d3200fd972e77d.tar.bz2 lua-6a98aa0bb0426acdf4a9ef75b1d3200fd972e77d.zip | |
new opcode LOADI (for loading immediate integers)
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 16 |
1 files changed, 12 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.111 2016/07/19 17:12:07 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.112 2016/12/22 13:08:50 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 | */ |
| @@ -343,7 +343,7 @@ static int codeextraarg (FuncState *fs, int a) { | |||
| 343 | ** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX' | 343 | ** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX' |
| 344 | ** instruction with "extra argument". | 344 | ** instruction with "extra argument". |
| 345 | */ | 345 | */ |
| 346 | int luaK_codek (FuncState *fs, int reg, int k) { | 346 | static int luaK_codek (FuncState *fs, int reg, int k) { |
| 347 | if (k <= MAXARG_Bx) | 347 | if (k <= MAXARG_Bx) |
| 348 | return luaK_codeABx(fs, OP_LOADK, reg, k); | 348 | return luaK_codeABx(fs, OP_LOADK, reg, k); |
| 349 | else { | 349 | else { |
| @@ -468,7 +468,7 @@ int luaK_stringK (FuncState *fs, TString *s) { | |||
| 468 | ** same value; conversion to 'void*' is used only for hashing, so there | 468 | ** same value; conversion to 'void*' is used only for hashing, so there |
| 469 | ** are no "precision" problems. | 469 | ** are no "precision" problems. |
| 470 | */ | 470 | */ |
| 471 | int luaK_intK (FuncState *fs, lua_Integer n) { | 471 | static int luaK_intK (FuncState *fs, lua_Integer n) { |
| 472 | TValue k, o; | 472 | TValue k, o; |
| 473 | setpvalue(&k, cast(void*, cast(size_t, n))); | 473 | setpvalue(&k, cast(void*, cast(size_t, n))); |
| 474 | setivalue(&o, n); | 474 | setivalue(&o, n); |
| @@ -507,6 +507,14 @@ static int nilK (FuncState *fs) { | |||
| 507 | } | 507 | } |
| 508 | 508 | ||
| 509 | 509 | ||
| 510 | void luaK_int (FuncState *fs, int reg, lua_Integer i) { | ||
| 511 | if (-MAXARG_sBx <= i && i <= MAXARG_sBx) | ||
| 512 | luaK_codeAsBx(fs, OP_LOADI, reg, cast_int(i)); | ||
| 513 | else | ||
| 514 | luaK_codek(fs, reg, luaK_intK(fs, i)); | ||
| 515 | } | ||
| 516 | |||
| 517 | |||
| 510 | /* | 518 | /* |
| 511 | ** Fix an expression to return the number of results 'nresults'. | 519 | ** Fix an expression to return the number of results 'nresults'. |
| 512 | ** Either 'e' is a multi-ret expression (function call or vararg) | 520 | ** Either 'e' is a multi-ret expression (function call or vararg) |
| @@ -612,7 +620,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { | |||
| 612 | break; | 620 | break; |
| 613 | } | 621 | } |
| 614 | case VKINT: { | 622 | case VKINT: { |
| 615 | luaK_codek(fs, reg, luaK_intK(fs, e->u.ival)); | 623 | luaK_int(fs, reg, e->u.ival); |
| 616 | break; | 624 | break; |
| 617 | } | 625 | } |
| 618 | case VRELOCABLE: { | 626 | case VRELOCABLE: { |
