diff options
| -rw-r--r-- | lcode.h | 4 | ||||
| -rw-r--r-- | lopcodes.c | 4 | ||||
| -rw-r--r-- | lopcodes.h | 3 | ||||
| -rw-r--r-- | lparser.c | 7 | ||||
| -rw-r--r-- | ltm.c | 4 | ||||
| -rw-r--r-- | ltm.h | 3 | ||||
| -rw-r--r-- | luaconf.h | 3 | ||||
| -rw-r--r-- | lvm.c | 43 |
8 files changed, 48 insertions, 23 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.h,v 1.39 2004/05/31 18:51:50 roberto Exp $ | 2 | ** $Id: lcode.h,v 1.40 2004/10/04 19:01:53 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 | 24 | ** grep "ORDER OPR" if you change these enums |
| 25 | */ | 25 | */ |
| 26 | typedef enum BinOpr { | 26 | typedef enum BinOpr { |
| 27 | OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_POW, | 27 | OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_MOD, OPR_POW, |
| 28 | OPR_CONCAT, | 28 | OPR_CONCAT, |
| 29 | OPR_NE, OPR_EQ, | 29 | OPR_NE, OPR_EQ, |
| 30 | OPR_LT, OPR_LE, OPR_GT, OPR_GE, | 30 | OPR_LT, OPR_LE, OPR_GT, OPR_GE, |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.c,v 1.29 2004/10/04 19:01:53 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.30 2004/12/02 12:59:10 roberto Exp roberto $ |
| 3 | ** See Copyright Notice in lua.h | 3 | ** See Copyright Notice in lua.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -32,6 +32,7 @@ const char *const luaP_opnames[NUM_OPCODES+1] = { | |||
| 32 | "SUB", | 32 | "SUB", |
| 33 | "MUL", | 33 | "MUL", |
| 34 | "DIV", | 34 | "DIV", |
| 35 | "MOD", | ||
| 35 | "POW", | 36 | "POW", |
| 36 | "UNM", | 37 | "UNM", |
| 37 | "NOT", | 38 | "NOT", |
| @@ -76,6 +77,7 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
| 76 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ | 77 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ |
| 77 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ | 78 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ |
| 78 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ | 79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ |
| 80 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ | ||
| 79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ | 81 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ |
| 80 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ | 82 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ |
| 81 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ | 83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.h,v 1.113 2004/10/04 19:07:42 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.114 2004/12/02 12:59:10 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 | */ |
| @@ -172,6 +172,7 @@ OP_ADD,/* A B C R(A) := RK(B) + RK(C) */ | |||
| 172 | OP_SUB,/* A B C R(A) := RK(B) - RK(C) */ | 172 | OP_SUB,/* A B C R(A) := RK(B) - RK(C) */ |
| 173 | OP_MUL,/* A B C R(A) := RK(B) * RK(C) */ | 173 | OP_MUL,/* A B C R(A) := RK(B) * RK(C) */ |
| 174 | OP_DIV,/* A B C R(A) := RK(B) / RK(C) */ | 174 | OP_DIV,/* A B C R(A) := RK(B) / RK(C) */ |
| 175 | OP_MOD,/* A B C R(A) := RK(B) % RK(C) */ | ||
| 175 | OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ | 176 | OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ |
| 176 | OP_UNM,/* A B R(A) := -R(B) */ | 177 | OP_UNM,/* A B R(A) := -R(B) */ |
| 177 | OP_NOT,/* A B R(A) := not R(B) */ | 178 | OP_NOT,/* A B R(A) := not R(B) */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 2.13 2005/01/05 18:20:51 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.14 2005/03/07 16:58:27 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 | */ |
| @@ -799,6 +799,7 @@ static BinOpr getbinopr (int op) { | |||
| 799 | case '-': return OPR_SUB; | 799 | case '-': return OPR_SUB; |
| 800 | case '*': return OPR_MULT; | 800 | case '*': return OPR_MULT; |
| 801 | case '/': return OPR_DIV; | 801 | case '/': return OPR_DIV; |
| 802 | case '%': return OPR_MOD; | ||
| 802 | case '^': return OPR_POW; | 803 | case '^': return OPR_POW; |
| 803 | case TK_CONCAT: return OPR_CONCAT; | 804 | case TK_CONCAT: return OPR_CONCAT; |
| 804 | case TK_NE: return OPR_NE; | 805 | case TK_NE: return OPR_NE; |
| @@ -818,9 +819,9 @@ static const struct { | |||
| 818 | lu_byte left; /* left priority for each binary operator */ | 819 | lu_byte left; /* left priority for each binary operator */ |
| 819 | lu_byte right; /* right priority */ | 820 | lu_byte right; /* right priority */ |
| 820 | } priority[] = { /* ORDER OPR */ | 821 | } priority[] = { /* ORDER OPR */ |
| 821 | {6, 6}, {6, 6}, {7, 7}, {7, 7}, /* arithmetic */ | 822 | {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */ |
| 822 | {10, 9}, {5, 4}, /* power and concat (right associative) */ | 823 | {10, 9}, {5, 4}, /* power and concat (right associative) */ |
| 823 | {3, 3}, {3, 3}, /* equality */ | 824 | {3, 3}, {3, 3}, /* equality and inequality */ |
| 824 | {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ | 825 | {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ |
| 825 | {2, 2}, {1, 1} /* logical (and/or) */ | 826 | {2, 2}, {1, 1} /* logical (and/or) */ |
| 826 | }; | 827 | }; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 2.2 2004/02/16 19:09:52 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.3 2004/04/30 20:13:38 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 | */ |
| @@ -31,7 +31,7 @@ void luaT_init (lua_State *L) { | |||
| 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ | 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ |
| 32 | "__index", "__newindex", | 32 | "__index", "__newindex", |
| 33 | "__gc", "__mode", "__eq", | 33 | "__gc", "__mode", "__eq", |
| 34 | "__add", "__sub", "__mul", "__div", | 34 | "__add", "__sub", "__mul", "__div", "__mod", |
| 35 | "__pow", "__unm", "__lt", "__le", | 35 | "__pow", "__unm", "__lt", "__le", |
| 36 | "__concat", "__call" | 36 | "__concat", "__call" |
| 37 | }; | 37 | }; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.h,v 1.42 2003/12/01 18:22:56 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 2.1 2003/12/10 12:13:36 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 | */ |
| @@ -25,6 +25,7 @@ typedef enum { | |||
| 25 | TM_SUB, | 25 | TM_SUB, |
| 26 | TM_MUL, | 26 | TM_MUL, |
| 27 | TM_DIV, | 27 | TM_DIV, |
| 28 | TM_MOD, | ||
| 28 | TM_POW, | 29 | TM_POW, |
| 29 | TM_UNM, | 30 | TM_UNM, |
| 30 | TM_LT, | 31 | TM_LT, |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luaconf.h,v 1.30 2005/02/28 15:59:11 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.31 2005/03/08 13:27:36 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 | */ |
| @@ -261,6 +261,7 @@ __inline int l_lrint (double flt) | |||
| 261 | #define num_lt(a,b) ((a)<(b)) | 261 | #define num_lt(a,b) ((a)<(b)) |
| 262 | #define num_le(a,b) ((a)<=(b)) | 262 | #define num_le(a,b) ((a)<=(b)) |
| 263 | #include <math.h> | 263 | #include <math.h> |
| 264 | #define num_mod(a,b) ((a) - floor((a)/(b))*(b)) | ||
| 264 | #define num_pow(a,b) pow(a,b) | 265 | #define num_pow(a,b) pow(a,b) |
| 265 | 266 | ||
| 266 | 267 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.27 2005/03/07 16:59:01 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.28 2005/03/07 18:27:34 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 | */ |
| @@ -334,12 +334,14 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb, | |||
| 334 | L->ci->savedpc = pc; | 334 | L->ci->savedpc = pc; |
| 335 | if ((b = luaV_tonumber(rb, &tempb)) != NULL && | 335 | if ((b = luaV_tonumber(rb, &tempb)) != NULL && |
| 336 | (c = luaV_tonumber(rc, &tempc)) != NULL) { | 336 | (c = luaV_tonumber(rc, &tempc)) != NULL) { |
| 337 | lua_Number nb = nvalue(b), nc = nvalue(c); | ||
| 337 | switch (op) { | 338 | switch (op) { |
| 338 | case TM_ADD: setnvalue(ra, num_add(nvalue(b), nvalue(c))); break; | 339 | case TM_ADD: setnvalue(ra, num_add(nb, nc)); break; |
| 339 | case TM_SUB: setnvalue(ra, num_sub(nvalue(b), nvalue(c))); break; | 340 | case TM_SUB: setnvalue(ra, num_sub(nb, nc)); break; |
| 340 | case TM_MUL: setnvalue(ra, num_mul(nvalue(b), nvalue(c))); break; | 341 | case TM_MUL: setnvalue(ra, num_mul(nb, nc)); break; |
| 341 | case TM_DIV: setnvalue(ra, num_div(nvalue(b), nvalue(c))); break; | 342 | case TM_DIV: setnvalue(ra, num_div(nb, nc)); break; |
| 342 | case TM_POW: setnvalue(ra, num_pow(nvalue(b), nvalue(c))); break; | 343 | case TM_MOD: setnvalue(ra, num_mod(nb, nc)); break; |
| 344 | case TM_POW: setnvalue(ra, num_pow(nb, nc)); break; | ||
| 343 | default: lua_assert(0); break; | 345 | default: lua_assert(0); break; |
| 344 | } | 346 | } |
| 345 | } | 347 | } |
| @@ -475,7 +477,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 475 | TValue *rb = RKB(i); | 477 | TValue *rb = RKB(i); |
| 476 | TValue *rc = RKC(i); | 478 | TValue *rc = RKC(i); |
| 477 | if (ttisnumber(rb) && ttisnumber(rc)) { | 479 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 478 | setnvalue(ra, num_add(nvalue(rb), nvalue(rc))); | 480 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 481 | setnvalue(ra, num_add(nb, nc)); | ||
| 479 | } | 482 | } |
| 480 | else | 483 | else |
| 481 | base = Arith(L, ra, rb, rc, TM_ADD, pc); /***/ | 484 | base = Arith(L, ra, rb, rc, TM_ADD, pc); /***/ |
| @@ -485,7 +488,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 485 | TValue *rb = RKB(i); | 488 | TValue *rb = RKB(i); |
| 486 | TValue *rc = RKC(i); | 489 | TValue *rc = RKC(i); |
| 487 | if (ttisnumber(rb) && ttisnumber(rc)) { | 490 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 488 | setnvalue(ra, num_sub(nvalue(rb), nvalue(rc))); | 491 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 492 | setnvalue(ra, num_sub(nb, nc)); | ||
| 489 | } | 493 | } |
| 490 | else | 494 | else |
| 491 | base = Arith(L, ra, rb, rc, TM_SUB, pc); /***/ | 495 | base = Arith(L, ra, rb, rc, TM_SUB, pc); /***/ |
| @@ -495,7 +499,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 495 | TValue *rb = RKB(i); | 499 | TValue *rb = RKB(i); |
| 496 | TValue *rc = RKC(i); | 500 | TValue *rc = RKC(i); |
| 497 | if (ttisnumber(rb) && ttisnumber(rc)) { | 501 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 498 | setnvalue(ra, num_mul(nvalue(rb), nvalue(rc))); | 502 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 503 | setnvalue(ra, num_mul(nb, nc)); | ||
| 499 | } | 504 | } |
| 500 | else | 505 | else |
| 501 | base = Arith(L, ra, rb, rc, TM_MUL, pc); /***/ | 506 | base = Arith(L, ra, rb, rc, TM_MUL, pc); /***/ |
| @@ -505,17 +510,30 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 505 | TValue *rb = RKB(i); | 510 | TValue *rb = RKB(i); |
| 506 | TValue *rc = RKC(i); | 511 | TValue *rc = RKC(i); |
| 507 | if (ttisnumber(rb) && ttisnumber(rc)) { | 512 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 508 | setnvalue(ra, num_div(nvalue(rb), nvalue(rc))); | 513 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 514 | setnvalue(ra, num_div(nb, nc)); | ||
| 509 | } | 515 | } |
| 510 | else | 516 | else |
| 511 | base = Arith(L, ra, rb, rc, TM_DIV, pc); /***/ | 517 | base = Arith(L, ra, rb, rc, TM_DIV, pc); /***/ |
| 512 | continue; | 518 | continue; |
| 513 | } | 519 | } |
| 520 | case OP_MOD: { | ||
| 521 | TValue *rb = RKB(i); | ||
| 522 | TValue *rc = RKC(i); | ||
| 523 | if (ttisnumber(rb) && ttisnumber(rc)) { | ||
| 524 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | ||
| 525 | setnvalue(ra, num_mod(nb, nc)); | ||
| 526 | } | ||
| 527 | else | ||
| 528 | base = Arith(L, ra, rb, rc, TM_MOD, pc); /***/ | ||
| 529 | continue; | ||
| 530 | } | ||
| 514 | case OP_POW: { | 531 | case OP_POW: { |
| 515 | TValue *rb = RKB(i); | 532 | TValue *rb = RKB(i); |
| 516 | TValue *rc = RKC(i); | 533 | TValue *rc = RKC(i); |
| 517 | if (ttisnumber(rb) && ttisnumber(rc)) { | 534 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 518 | setnvalue(ra, num_pow(nvalue(rb), nvalue(rc))); | 535 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 536 | setnvalue(ra, num_pow(nb, nc)); | ||
| 519 | } | 537 | } |
| 520 | else | 538 | else |
| 521 | base = Arith(L, ra, rb, rc, TM_POW, pc); /***/ | 539 | base = Arith(L, ra, rb, rc, TM_POW, pc); /***/ |
| @@ -525,7 +543,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
| 525 | const TValue *rb = RB(i); | 543 | const TValue *rb = RB(i); |
| 526 | TValue temp; | 544 | TValue temp; |
| 527 | if (tonumber(rb, &temp)) { | 545 | if (tonumber(rb, &temp)) { |
| 528 | setnvalue(ra, num_unm(nvalue(rb))); | 546 | lua_Number nb = nvalue(rb); |
| 547 | setnvalue(ra, num_unm(nb)); | ||
| 529 | } | 548 | } |
| 530 | else { | 549 | else { |
| 531 | setnilvalue(&temp); | 550 | setnilvalue(&temp); |
