diff options
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.17 2005/09/30 14:23:33 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.19 2005/10/13 12:21:51 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 | */ |
@@ -27,7 +27,7 @@ | |||
27 | #define hasjumps(e) ((e)->t != (e)->f) | 27 | #define hasjumps(e) ((e)->t != (e)->f) |
28 | 28 | ||
29 | 29 | ||
30 | static int isnumeral(FuncState *fs, expdesc *e) { | 30 | static int isnumeral(expdesc *e) { |
31 | return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP); | 31 | return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP); |
32 | } | 32 | } |
33 | 33 | ||
@@ -627,21 +627,21 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { | |||
627 | } | 627 | } |
628 | 628 | ||
629 | 629 | ||
630 | static int constfolding (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { | 630 | static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { |
631 | lua_Number v1, v2, r; | 631 | lua_Number v1, v2, r; |
632 | if (!isnumeral(fs, e1) || !isnumeral(fs, e2)) return 0; | 632 | if (!isnumeral(e1) || !isnumeral(e2)) return 0; |
633 | v1 = e1->u.nval; | 633 | v1 = e1->u.nval; |
634 | v2 = e2->u.nval; | 634 | v2 = e2->u.nval; |
635 | switch (op) { | 635 | switch (op) { |
636 | case OP_ADD: r = luai_numadd(fs->L, v1, v2); break; | 636 | case OP_ADD: r = luai_numadd(v1, v2); break; |
637 | case OP_SUB: r = luai_numsub(fs->L, v1, v2); break; | 637 | case OP_SUB: r = luai_numsub(v1, v2); break; |
638 | case OP_MUL: r = luai_nummul(fs->L, v1, v2); break; | 638 | case OP_MUL: r = luai_nummul(v1, v2); break; |
639 | case OP_DIV: | 639 | case OP_DIV: |
640 | if (v2 == 0) return 0; /* do not attempt to divide by 0 */ | 640 | if (v2 == 0) return 0; /* do not attempt to divide by 0 */ |
641 | r = luai_numdiv(fs->L, v1, v2); break; | 641 | r = luai_numdiv(v1, v2); break; |
642 | case OP_MOD: r = luai_nummod(fs->L, v1, v2); break; | 642 | case OP_MOD: r = luai_nummod(v1, v2); break; |
643 | case OP_POW: r = luai_numpow(fs->L, v1, v2); break; | 643 | case OP_POW: r = luai_numpow(v1, v2); break; |
644 | case OP_UNM: r = luai_numunm(fs->L, v1); break; | 644 | case OP_UNM: r = luai_numunm(v1); break; |
645 | case OP_LEN: return 0; /* no constant folding for 'len' */ | 645 | case OP_LEN: return 0; /* no constant folding for 'len' */ |
646 | default: lua_assert(0); r = 0; break; | 646 | default: lua_assert(0); r = 0; break; |
647 | } | 647 | } |
@@ -652,7 +652,7 @@ static int constfolding (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { | |||
652 | 652 | ||
653 | 653 | ||
654 | static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { | 654 | static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { |
655 | if (constfolding(fs, op, e1, e2)) | 655 | if (constfolding(op, e1, e2)) |
656 | return; | 656 | return; |
657 | else { | 657 | else { |
658 | int o1 = luaK_exp2RK(fs, e1); | 658 | int o1 = luaK_exp2RK(fs, e1); |
@@ -717,7 +717,7 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { | |||
717 | break; | 717 | break; |
718 | } | 718 | } |
719 | default: { | 719 | default: { |
720 | if (!isnumeral(fs, v)) luaK_exp2RK(fs, v); | 720 | if (!isnumeral(v)) luaK_exp2RK(fs, v); |
721 | break; | 721 | break; |
722 | } | 722 | } |
723 | } | 723 | } |