diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-21 15:56:33 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-21 15:56:33 -0300 |
| commit | fbc23d02456929a24bbad4eee2bd9d6ed8526ba7 (patch) | |
| tree | a3951cb50721e882b605561a4fa29b8824991577 /lcode.c | |
| parent | 81a8845e4f10851693cbe438520a4c07d347a731 (diff) | |
| download | lua-fbc23d02456929a24bbad4eee2bd9d6ed8526ba7.tar.gz lua-fbc23d02456929a24bbad4eee2bd9d6ed8526ba7.tar.bz2 lua-fbc23d02456929a24bbad4eee2bd9d6ed8526ba7.zip | |
details
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 45 |
1 files changed, 14 insertions, 31 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 1.109 2002/08/05 14:07:34 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.110 2002/08/20 20:03:05 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 | */ |
| @@ -616,38 +616,21 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { | |||
| 616 | 616 | ||
| 617 | static void codebinop (FuncState *fs, expdesc *res, BinOpr op, | 617 | static void codebinop (FuncState *fs, expdesc *res, BinOpr op, |
| 618 | int o1, int o2) { | 618 | int o1, int o2) { |
| 619 | switch (op) { | 619 | if (op <= OPR_POW) { /* arithmetic operator? */ |
| 620 | case OPR_SUB: | 620 | OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD); /* ORDER OP */ |
| 621 | case OPR_DIV: | 621 | res->info = luaK_codeABC(fs, opc, 0, o1, o2); |
| 622 | case OPR_POW: | 622 | res->k = VRELOCABLE; |
| 623 | case OPR_ADD: | 623 | } |
| 624 | case OPR_MULT: { /* ORDER OPR */ | 624 | else { /* test operator */ |
| 625 | OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD); | 625 | static const OpCode ops[] = {OP_EQ, OP_EQ, OP_LT, OP_LE, OP_LT, OP_LE}; |
| 626 | res->info = luaK_codeABC(fs, opc, 0, o1, o2); | 626 | int cond = 1; |
| 627 | res->k = VRELOCABLE; | 627 | if (op >= OPR_GT) { /* `>' or `>='? */ |
| 628 | break; | 628 | int temp; /* exchange args and replace by `<' or `<=' */ |
| 629 | } | ||
| 630 | case OPR_NE: | ||
| 631 | case OPR_EQ: { | ||
| 632 | res->info = luaK_condjump(fs, OP_EQ, (op == OPR_EQ), o1, o2); | ||
| 633 | res->k = VJMP; | ||
| 634 | break; | ||
| 635 | } | ||
| 636 | case OPR_GT: | ||
| 637 | case OPR_GE: { /* ORDER OPR */ | ||
| 638 | int temp; | ||
| 639 | temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ | 629 | temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ |
| 640 | op -= 2; /* GT -> LT, GE -> LE */ | ||
| 641 | /* go through */ | ||
| 642 | } | ||
| 643 | case OPR_LT: | ||
| 644 | case OPR_LE: { | ||
| 645 | OpCode opc = cast(OpCode, (op - OPR_LT) + OP_LT); | ||
| 646 | res->info = luaK_condjump(fs, opc, 1, o1, o2); | ||
| 647 | res->k = VJMP; | ||
| 648 | break; | ||
| 649 | } | 630 | } |
| 650 | default: lua_assert(0); | 631 | else if (op == OPR_NE) cond = 0; |
| 632 | res->info = luaK_condjump(fs, ops[op - OPR_NE], cond, o1, o2); | ||
| 633 | res->k = VJMP; | ||
| 651 | } | 634 | } |
| 652 | } | 635 | } |
| 653 | 636 | ||
