diff options
-rw-r--r-- | lcode.c | 9 | ||||
-rw-r--r-- | lcode.h | 4 | ||||
-rw-r--r-- | ldebug.c | 3 | ||||
-rw-r--r-- | llex.c | 9 | ||||
-rw-r--r-- | llex.h | 5 | ||||
-rw-r--r-- | lopcodes.c | 4 | ||||
-rw-r--r-- | lopcodes.h | 3 | ||||
-rw-r--r-- | lparser.c | 6 | ||||
-rw-r--r-- | ltests.c | 4 | ||||
-rw-r--r-- | ltm.c | 4 | ||||
-rw-r--r-- | ltm.h | 3 | ||||
-rw-r--r-- | lua.h | 9 | ||||
-rw-r--r-- | luaconf.h | 3 | ||||
-rw-r--r-- | lvm.c | 17 |
14 files changed, 56 insertions, 27 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.64 2013/04/16 18:46:28 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.65 2013/04/25 19:35:19 roberto Exp $ |
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 | */ |
@@ -732,7 +732,7 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { | |||
732 | static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { | 732 | static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { |
733 | lua_Number r; | 733 | lua_Number r; |
734 | if (!isnumeral(e1) || !isnumeral(e2)) return 0; | 734 | if (!isnumeral(e1) || !isnumeral(e2)) return 0; |
735 | if ((op == OP_DIV || op == OP_MOD) && e2->u.nval == 0) | 735 | if ((op == OP_DIV || op == OP_IDIV || op == OP_MOD) && e2->u.nval == 0) |
736 | return 0; /* do not attempt to divide by 0 */ | 736 | return 0; /* do not attempt to divide by 0 */ |
737 | r = luaO_arith(op - OP_ADD + LUA_OPADD, e1->u.nval, e2->u.nval); | 737 | r = luaO_arith(op - OP_ADD + LUA_OPADD, e1->u.nval, e2->u.nval); |
738 | e1->u.nval = r; | 738 | e1->u.nval = r; |
@@ -816,7 +816,8 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { | |||
816 | luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ | 816 | luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ |
817 | break; | 817 | break; |
818 | } | 818 | } |
819 | case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: | 819 | case OPR_ADD: case OPR_SUB: |
820 | case OPR_MUL: case OPR_DIV: case OPR_IDIV: | ||
820 | case OPR_MOD: case OPR_POW: { | 821 | case OPR_MOD: case OPR_POW: { |
821 | if (!isnumeral(v)) luaK_exp2RK(fs, v); | 822 | if (!isnumeral(v)) luaK_exp2RK(fs, v); |
822 | break; | 823 | break; |
@@ -861,7 +862,7 @@ void luaK_posfix (FuncState *fs, BinOpr op, | |||
861 | break; | 862 | break; |
862 | } | 863 | } |
863 | case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: | 864 | case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: |
864 | case OPR_MOD: case OPR_POW: { | 865 | case OPR_IDIV: case OPR_MOD: case OPR_POW: { |
865 | codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line); | 866 | codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line); |
866 | break; | 867 | break; |
867 | } | 868 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.h,v 1.58 2011/08/30 16:26:41 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.59 2013/04/25 19:35:19 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 | */ |
@@ -24,7 +24,7 @@ | |||
24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) | 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) |
25 | */ | 25 | */ |
26 | typedef enum BinOpr { | 26 | typedef enum BinOpr { |
27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, | 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_IDIV, OPR_MOD, OPR_POW, |
28 | OPR_CONCAT, | 28 | OPR_CONCAT, |
29 | OPR_EQ, OPR_LT, OPR_LE, | 29 | OPR_EQ, OPR_LT, OPR_LE, |
30 | OPR_NE, OPR_GT, OPR_GE, | 30 | OPR_NE, OPR_GT, OPR_GE, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.90 2012/08/16 17:34:28 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.91 2013/04/25 15:59:42 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -453,6 +453,7 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { | |||
453 | case OP_SUB: tm = TM_SUB; break; | 453 | case OP_SUB: tm = TM_SUB; break; |
454 | case OP_MUL: tm = TM_MUL; break; | 454 | case OP_MUL: tm = TM_MUL; break; |
455 | case OP_DIV: tm = TM_DIV; break; | 455 | case OP_DIV: tm = TM_DIV; break; |
456 | case OP_IDIV: tm = TM_IDIV; break; | ||
456 | case OP_MOD: tm = TM_MOD; break; | 457 | case OP_MOD: tm = TM_MOD; break; |
457 | case OP_POW: tm = TM_POW; break; | 458 | case OP_POW: tm = TM_POW; break; |
458 | case OP_UNM: tm = TM_UNM; break; | 459 | case OP_UNM: tm = TM_UNM; break; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.63 2013/03/16 21:10:18 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.64 2013/04/16 18:46:28 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -38,7 +38,7 @@ static const char *const luaX_tokens [] = { | |||
38 | "end", "false", "for", "function", "goto", "if", | 38 | "end", "false", "for", "function", "goto", "if", |
39 | "in", "local", "nil", "not", "or", "repeat", | 39 | "in", "local", "nil", "not", "or", "repeat", |
40 | "return", "then", "true", "until", "while", | 40 | "return", "then", "true", "until", "while", |
41 | "..", "...", "==", ">=", "<=", "~=", "::", "<eof>", | 41 | "//", "..", "...", "==", ">=", "<=", "~=", "::", "<eof>", |
42 | "<number>", "<number>", "<name>", "<string>" | 42 | "<number>", "<number>", "<name>", "<string>" |
43 | }; | 43 | }; |
44 | 44 | ||
@@ -464,6 +464,11 @@ static int llex (LexState *ls, SemInfo *seminfo) { | |||
464 | if (ls->current != '=') return '>'; | 464 | if (ls->current != '=') return '>'; |
465 | else { next(ls); return TK_GE; } | 465 | else { next(ls); return TK_GE; } |
466 | } | 466 | } |
467 | case '/': { | ||
468 | next(ls); | ||
469 | if (ls->current != '/') return '/'; | ||
470 | else { next(ls); return TK_IDIV; } | ||
471 | } | ||
467 | case '~': { | 472 | case '~': { |
468 | next(ls); | 473 | next(ls); |
469 | if (ls->current != '=') return '~'; | 474 | if (ls->current != '=') return '~'; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.h,v 1.72 2011/11/30 12:43:51 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.73 2013/04/16 18:46:28 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -26,7 +26,8 @@ enum RESERVED { | |||
26 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, | 26 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, |
27 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, | 27 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, |
28 | /* other terminal symbols */ | 28 | /* other terminal symbols */ |
29 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_DBCOLON, TK_EOS, | 29 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, |
30 | TK_DBCOLON, TK_EOS, | ||
30 | TK_FLT, TK_INT, TK_NAME, TK_STRING | 31 | TK_FLT, TK_INT, TK_NAME, TK_STRING |
31 | }; | 32 | }; |
32 | 33 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.c,v 1.48 2011/04/19 16:22:13 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.49 2012/05/14 13:34:18 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 | */ |
@@ -32,6 +32,7 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { | |||
32 | "SUB", | 32 | "SUB", |
33 | "MUL", | 33 | "MUL", |
34 | "DIV", | 34 | "DIV", |
35 | "IDIV", | ||
35 | "MOD", | 36 | "MOD", |
36 | "POW", | 37 | "POW", |
37 | "UNM", | 38 | "UNM", |
@@ -80,6 +81,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
80 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ | 81 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ |
81 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ | 82 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ |
82 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ | 83 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ |
84 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_IDIV */ | ||
83 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ | 85 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ |
84 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ | 86 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ |
85 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ | 87 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.141 2011/04/19 16:22:13 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.142 2011/07/15 12:50:29 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 | */ |
@@ -188,6 +188,7 @@ OP_ADD,/* A B C R(A) := RK(B) + RK(C) */ | |||
188 | OP_SUB,/* A B C R(A) := RK(B) - RK(C) */ | 188 | OP_SUB,/* A B C R(A) := RK(B) - RK(C) */ |
189 | OP_MUL,/* A B C R(A) := RK(B) * RK(C) */ | 189 | OP_MUL,/* A B C R(A) := RK(B) * RK(C) */ |
190 | OP_DIV,/* A B C R(A) := RK(B) / RK(C) */ | 190 | OP_DIV,/* A B C R(A) := RK(B) / RK(C) */ |
191 | OP_IDIV,/* A B C R(A) := RK(B) // RK(C) */ | ||
191 | OP_MOD,/* A B C R(A) := RK(B) % RK(C) */ | 192 | OP_MOD,/* A B C R(A) := RK(B) % RK(C) */ |
192 | OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ | 193 | OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ |
193 | OP_UNM,/* A B R(A) := -R(B) */ | 194 | OP_UNM,/* A B R(A) := -R(B) */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.131 2013/04/16 18:46:28 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.132 2013/04/25 19:35:19 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1005,6 +1005,7 @@ static BinOpr getbinopr (int op) { | |||
1005 | case '-': return OPR_SUB; | 1005 | case '-': return OPR_SUB; |
1006 | case '*': return OPR_MUL; | 1006 | case '*': return OPR_MUL; |
1007 | case '/': return OPR_DIV; | 1007 | case '/': return OPR_DIV; |
1008 | case TK_IDIV: return OPR_IDIV; | ||
1008 | case '%': return OPR_MOD; | 1009 | case '%': return OPR_MOD; |
1009 | case '^': return OPR_POW; | 1010 | case '^': return OPR_POW; |
1010 | case TK_CONCAT: return OPR_CONCAT; | 1011 | case TK_CONCAT: return OPR_CONCAT; |
@@ -1025,7 +1026,8 @@ static const struct { | |||
1025 | lu_byte left; /* left priority for each binary operator */ | 1026 | lu_byte left; /* left priority for each binary operator */ |
1026 | lu_byte right; /* right priority */ | 1027 | lu_byte right; /* right priority */ |
1027 | } priority[] = { /* ORDER OPR */ | 1028 | } priority[] = { /* ORDER OPR */ |
1028 | {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */ | 1029 | {6, 6}, {6, 6}, /* '+' '-' */ |
1030 | {7, 7}, {7, 7}, {7, 7}, {7, 7}, /* '*' '/' '//' '%' */ | ||
1029 | {10, 9}, {5, 4}, /* ^, .. (right associative) */ | 1031 | {10, 9}, {5, 4}, /* ^, .. (right associative) */ |
1030 | {3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */ | 1032 | {3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */ |
1031 | {3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */ | 1033 | {3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.135 2013/03/16 21:10:18 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.136 2013/04/24 19:41:48 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1198,7 +1198,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
1198 | } | 1198 | } |
1199 | } | 1199 | } |
1200 | else if EQ("arith") { | 1200 | else if EQ("arith") { |
1201 | static char ops[] = "+-*/%^_"; | 1201 | static char ops[] = "+-*/\\%^_"; /* '\' -> '//'; '_' -> '..' */ |
1202 | int op; | 1202 | int op; |
1203 | skip(&pc); | 1203 | skip(&pc); |
1204 | op = strchr(ops, *pc++) - ops; | 1204 | op = strchr(ops, *pc++) - ops; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 2.16 2013/04/25 15:59:42 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.17 2013/04/25 16:07:52 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -35,7 +35,7 @@ void luaT_init (lua_State *L) { | |||
35 | static const char *const luaT_eventname[] = { /* ORDER TM */ | 35 | static const char *const luaT_eventname[] = { /* ORDER TM */ |
36 | "__index", "__newindex", | 36 | "__index", "__newindex", |
37 | "__gc", "__mode", "__len", "__eq", | 37 | "__gc", "__mode", "__len", "__eq", |
38 | "__add", "__sub", "__mul", "__div", "__mod", | 38 | "__add", "__sub", "__mul", "__div", "__idiv", "__mod", |
39 | "__pow", "__unm", "__lt", "__le", | 39 | "__pow", "__unm", "__lt", "__le", |
40 | "__concat", "__call" | 40 | "__concat", "__call" |
41 | }; | 41 | }; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 2.13 2013/04/25 15:59:42 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 2.14 2013/04/25 16:07:52 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -26,6 +26,7 @@ typedef enum { | |||
26 | TM_SUB, | 26 | TM_SUB, |
27 | TM_MUL, | 27 | TM_MUL, |
28 | TM_DIV, | 28 | TM_DIV, |
29 | TM_IDIV, | ||
29 | TM_MOD, | 30 | TM_MOD, |
30 | TM_POW, | 31 | TM_POW, |
31 | TM_UNM, | 32 | TM_UNM, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.285 2013/03/15 13:04:22 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.286 2013/04/25 13:52:49 roberto Exp roberto $ |
3 | ** Lua - A Scripting Language | 3 | ** Lua - A Scripting Language |
4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
@@ -186,9 +186,10 @@ LUA_API const void *(lua_topointer) (lua_State *L, int idx); | |||
186 | #define LUA_OPSUB 1 | 186 | #define LUA_OPSUB 1 |
187 | #define LUA_OPMUL 2 | 187 | #define LUA_OPMUL 2 |
188 | #define LUA_OPDIV 3 | 188 | #define LUA_OPDIV 3 |
189 | #define LUA_OPMOD 4 | 189 | #define LUA_OPIDIV 4 |
190 | #define LUA_OPPOW 5 | 190 | #define LUA_OPMOD 5 |
191 | #define LUA_OPUNM 6 | 191 | #define LUA_OPPOW 6 |
192 | #define LUA_OPUNM 7 | ||
192 | 193 | ||
193 | LUA_API void (lua_arith) (lua_State *L, int op); | 194 | LUA_API void (lua_arith) (lua_State *L, int op); |
194 | 195 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.176 2013/03/16 21:10:18 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.177 2013/04/25 13:52:13 roberto Exp roberto $ |
3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -435,6 +435,7 @@ | |||
435 | /* the following operations need the math library */ | 435 | /* the following operations need the math library */ |
436 | #if defined(lobject_c) || defined(lvm_c) | 436 | #if defined(lobject_c) || defined(lvm_c) |
437 | #include <math.h> | 437 | #include <math.h> |
438 | #define luai_numidiv(L,a,b) (l_mathop(floor)((a)/(b))) | ||
438 | #define luai_nummod(L,a,b) ((a) - l_mathop(floor)((a)/(b))*(b)) | 439 | #define luai_nummod(L,a,b) ((a) - l_mathop(floor)((a)/(b))*(b)) |
439 | #define luai_numpow(L,a,b) (l_mathop(pow)(a,b)) | 440 | #define luai_numpow(L,a,b) (l_mathop(pow)(a,b)) |
440 | #endif | 441 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.161 2013/04/25 19:12:41 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.162 2013/04/25 19:50:02 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 | */ |
@@ -404,7 +404,7 @@ void luaV_finishOp (lua_State *L) { | |||
404 | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ | 404 | Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ |
405 | OpCode op = GET_OPCODE(inst); | 405 | OpCode op = GET_OPCODE(inst); |
406 | switch (op) { /* finish its execution */ | 406 | switch (op) { /* finish its execution */ |
407 | case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: | 407 | case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_IDIV: |
408 | case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN: | 408 | case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN: |
409 | case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: { | 409 | case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: { |
410 | setobjs2s(L, base + GETARG_A(inst), --L->top); | 410 | setobjs2s(L, base + GETARG_A(inst), --L->top); |
@@ -640,6 +640,19 @@ void luaV_execute (lua_State *L) { | |||
640 | } | 640 | } |
641 | else { Protect(luaV_arith(L, ra, rb, rc, TM_DIV)); } | 641 | else { Protect(luaV_arith(L, ra, rb, rc, TM_DIV)); } |
642 | ) | 642 | ) |
643 | vmcase(OP_IDIV, /* integer division */ | ||
644 | TValue *rb = RKB(i); | ||
645 | TValue *rc = RKC(i); | ||
646 | if (ttisinteger(rb) && ttisinteger(rc)) { | ||
647 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | ||
648 | setivalue(ra, luaV_div(L, ib, ic)); | ||
649 | } | ||
650 | else if (ttisnumber(rb) && ttisnumber(rc)) { | ||
651 | lua_Number nb = nvalue(rb); lua_Number nc = nvalue(rc); | ||
652 | setnvalue(ra, luai_numidiv(L, nb, nc)); | ||
653 | } | ||
654 | else { Protect(luaV_arith(L, ra, rb, rc, TM_IDIV)); } | ||
655 | ) | ||
643 | vmcase(OP_MOD, | 656 | vmcase(OP_MOD, |
644 | TValue *rb = RKB(i); | 657 | TValue *rb = RKB(i); |
645 | TValue *rc = RKC(i); | 658 | TValue *rc = RKC(i); |