diff options
| -rw-r--r-- | lcode.c | 26 | ||||
| -rw-r--r-- | lobject.c | 4 | ||||
| -rw-r--r-- | ltable.c | 10 | ||||
| -rw-r--r-- | lvm.c | 42 |
4 files changed, 41 insertions, 41 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 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.17 2005/07/31 17:11:50 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.18 2005/08/01 04:22:23 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -75,7 +75,7 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) { | |||
| 75 | case LUA_TNIL: | 75 | case LUA_TNIL: |
| 76 | return 1; | 76 | return 1; |
| 77 | case LUA_TNUMBER: | 77 | case LUA_TNUMBER: |
| 78 | return luai_numeq(L, nvalue(t1), nvalue(t2)); | 78 | return luai_numeq(nvalue(t1), nvalue(t2)); |
| 79 | case LUA_TBOOLEAN: | 79 | case LUA_TBOOLEAN: |
| 80 | return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ | 80 | return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ |
| 81 | case LUA_TLIGHTUSERDATA: | 81 | case LUA_TLIGHTUSERDATA: |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.25 2005/05/31 14:25:18 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.26 2005/07/11 14:01:37 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -120,7 +120,7 @@ static int arrayindex (const TValue *key) { | |||
| 120 | lua_Number n = nvalue(key); | 120 | lua_Number n = nvalue(key); |
| 121 | int k; | 121 | int k; |
| 122 | lua_number2int(k, n); | 122 | lua_number2int(k, n); |
| 123 | if (luai_numeq(L, cast(lua_Number, k), nvalue(key))) | 123 | if (luai_numeq(cast(lua_Number, k), nvalue(key))) |
| 124 | return k; | 124 | return k; |
| 125 | } | 125 | } |
| 126 | return -1; /* `key' did not match some condition */ | 126 | return -1; /* `key' did not match some condition */ |
| @@ -437,7 +437,7 @@ const TValue *luaH_getnum (Table *t, int key) { | |||
| 437 | lua_Number nk = cast(lua_Number, key); | 437 | lua_Number nk = cast(lua_Number, key); |
| 438 | Node *n = hashnum(t, nk); | 438 | Node *n = hashnum(t, nk); |
| 439 | do { /* check whether `key' is somewhere in the chain */ | 439 | do { /* check whether `key' is somewhere in the chain */ |
| 440 | if (ttisnumber(gkey(n)) && luai_numeq(L, nvalue(gkey(n)), nk)) | 440 | if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) |
| 441 | return gval(n); /* that's it */ | 441 | return gval(n); /* that's it */ |
| 442 | else n = gnext(n); | 442 | else n = gnext(n); |
| 443 | } while (n); | 443 | } while (n); |
| @@ -471,7 +471,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { | |||
| 471 | int k; | 471 | int k; |
| 472 | lua_Number n = nvalue(key); | 472 | lua_Number n = nvalue(key); |
| 473 | lua_number2int(k, n); | 473 | lua_number2int(k, n); |
| 474 | if (luai_numeq(L, cast(lua_Number, k), nvalue(key))) /* index is int? */ | 474 | if (luai_numeq(cast(lua_Number, k), nvalue(key))) /* index is int? */ |
| 475 | return luaH_getnum(t, k); /* use specialized version */ | 475 | return luaH_getnum(t, k); /* use specialized version */ |
| 476 | /* else go through */ | 476 | /* else go through */ |
| 477 | } | 477 | } |
| @@ -495,7 +495,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { | |||
| 495 | return cast(TValue *, p); | 495 | return cast(TValue *, p); |
| 496 | else { | 496 | else { |
| 497 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); | 497 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); |
| 498 | else if (ttisnumber(key) && !luai_numeq(L, nvalue(key), nvalue(key))) | 498 | else if (ttisnumber(key) && !luai_numeq(nvalue(key), nvalue(key))) |
| 499 | luaG_runerror(L, "table index is NaN"); | 499 | luaG_runerror(L, "table index is NaN"); |
| 500 | return newkey(L, t, key); | 500 | return newkey(L, t, key); |
| 501 | } | 501 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.56 2005/10/03 14:01:26 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.57 2005/10/13 12:21:26 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 | */ |
| @@ -225,7 +225,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { | |||
| 225 | if (ttype(l) != ttype(r)) | 225 | if (ttype(l) != ttype(r)) |
| 226 | return luaG_ordererror(L, l, r); | 226 | return luaG_ordererror(L, l, r); |
| 227 | else if (ttisnumber(l)) | 227 | else if (ttisnumber(l)) |
| 228 | return luai_numlt(L, nvalue(l), nvalue(r)); | 228 | return luai_numlt(nvalue(l), nvalue(r)); |
| 229 | else if (ttisstring(l)) | 229 | else if (ttisstring(l)) |
| 230 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; | 230 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; |
| 231 | else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) | 231 | else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) |
| @@ -239,7 +239,7 @@ static int lessequal (lua_State *L, const TValue *l, const TValue *r) { | |||
| 239 | if (ttype(l) != ttype(r)) | 239 | if (ttype(l) != ttype(r)) |
| 240 | return luaG_ordererror(L, l, r); | 240 | return luaG_ordererror(L, l, r); |
| 241 | else if (ttisnumber(l)) | 241 | else if (ttisnumber(l)) |
| 242 | return luai_numle(L, nvalue(l), nvalue(r)); | 242 | return luai_numle(nvalue(l), nvalue(r)); |
| 243 | else if (ttisstring(l)) | 243 | else if (ttisstring(l)) |
| 244 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; | 244 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; |
| 245 | else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ | 245 | else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ |
| @@ -255,7 +255,7 @@ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { | |||
| 255 | lua_assert(ttype(t1) == ttype(t2)); | 255 | lua_assert(ttype(t1) == ttype(t2)); |
| 256 | switch (ttype(t1)) { | 256 | switch (ttype(t1)) { |
| 257 | case LUA_TNIL: return 1; | 257 | case LUA_TNIL: return 1; |
| 258 | case LUA_TNUMBER: return luai_numeq(L, nvalue(t1), nvalue(t2)); | 258 | case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); |
| 259 | case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ | 259 | case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ |
| 260 | case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); | 260 | case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); |
| 261 | case LUA_TUSERDATA: { | 261 | case LUA_TUSERDATA: { |
| @@ -318,13 +318,13 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, | |||
| 318 | (c = luaV_tonumber(rc, &tempc)) != NULL) { | 318 | (c = luaV_tonumber(rc, &tempc)) != NULL) { |
| 319 | lua_Number nb = nvalue(b), nc = nvalue(c); | 319 | lua_Number nb = nvalue(b), nc = nvalue(c); |
| 320 | switch (op) { | 320 | switch (op) { |
| 321 | case TM_ADD: setnvalue(ra, luai_numadd(L, nb, nc)); break; | 321 | case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; |
| 322 | case TM_SUB: setnvalue(ra, luai_numsub(L, nb, nc)); break; | 322 | case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; |
| 323 | case TM_MUL: setnvalue(ra, luai_nummul(L, nb, nc)); break; | 323 | case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; |
| 324 | case TM_DIV: setnvalue(ra, luai_numdiv(L, nb, nc)); break; | 324 | case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; |
| 325 | case TM_MOD: setnvalue(ra, luai_nummod(L, nb, nc)); break; | 325 | case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; |
| 326 | case TM_POW: setnvalue(ra, luai_numpow(L, nb, nc)); break; | 326 | case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; |
| 327 | case TM_UNM: setnvalue(ra, luai_numunm(L, nb)); break; | 327 | case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; |
| 328 | default: lua_assert(0); break; | 328 | default: lua_assert(0); break; |
| 329 | } | 329 | } |
| 330 | } | 330 | } |
| @@ -458,7 +458,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 458 | TValue *rc = RKC(i); | 458 | TValue *rc = RKC(i); |
| 459 | if (ttisnumber(rb) && ttisnumber(rc)) { | 459 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 460 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 460 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 461 | setnvalue(ra, luai_numadd(L, nb, nc)); | 461 | setnvalue(ra, luai_numadd(nb, nc)); |
| 462 | } | 462 | } |
| 463 | else | 463 | else |
| 464 | Protect(Arith(L, ra, rb, rc, TM_ADD)); | 464 | Protect(Arith(L, ra, rb, rc, TM_ADD)); |
| @@ -469,7 +469,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 469 | TValue *rc = RKC(i); | 469 | TValue *rc = RKC(i); |
| 470 | if (ttisnumber(rb) && ttisnumber(rc)) { | 470 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 471 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 471 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 472 | setnvalue(ra, luai_numsub(L, nb, nc)); | 472 | setnvalue(ra, luai_numsub(nb, nc)); |
| 473 | } | 473 | } |
| 474 | else | 474 | else |
| 475 | Protect(Arith(L, ra, rb, rc, TM_SUB)); | 475 | Protect(Arith(L, ra, rb, rc, TM_SUB)); |
| @@ -480,7 +480,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 480 | TValue *rc = RKC(i); | 480 | TValue *rc = RKC(i); |
| 481 | if (ttisnumber(rb) && ttisnumber(rc)) { | 481 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 482 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 482 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 483 | setnvalue(ra, luai_nummul(L, nb, nc)); | 483 | setnvalue(ra, luai_nummul(nb, nc)); |
| 484 | } | 484 | } |
| 485 | else | 485 | else |
| 486 | Protect(Arith(L, ra, rb, rc, TM_MUL)); | 486 | Protect(Arith(L, ra, rb, rc, TM_MUL)); |
| @@ -491,7 +491,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 491 | TValue *rc = RKC(i); | 491 | TValue *rc = RKC(i); |
| 492 | if (ttisnumber(rb) && ttisnumber(rc)) { | 492 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 493 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 493 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 494 | setnvalue(ra, luai_numdiv(L, nb, nc)); | 494 | setnvalue(ra, luai_numdiv(nb, nc)); |
| 495 | } | 495 | } |
| 496 | else | 496 | else |
| 497 | Protect(Arith(L, ra, rb, rc, TM_DIV)); | 497 | Protect(Arith(L, ra, rb, rc, TM_DIV)); |
| @@ -502,7 +502,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 502 | TValue *rc = RKC(i); | 502 | TValue *rc = RKC(i); |
| 503 | if (ttisnumber(rb) && ttisnumber(rc)) { | 503 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 504 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 504 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 505 | setnvalue(ra, luai_nummod(L, nb, nc)); | 505 | setnvalue(ra, luai_nummod(nb, nc)); |
| 506 | } | 506 | } |
| 507 | else | 507 | else |
| 508 | Protect(Arith(L, ra, rb, rc, TM_MOD)); | 508 | Protect(Arith(L, ra, rb, rc, TM_MOD)); |
| @@ -513,7 +513,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 513 | TValue *rc = RKC(i); | 513 | TValue *rc = RKC(i); |
| 514 | if (ttisnumber(rb) && ttisnumber(rc)) { | 514 | if (ttisnumber(rb) && ttisnumber(rc)) { |
| 515 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 515 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
| 516 | setnvalue(ra, luai_numpow(L, nb, nc)); | 516 | setnvalue(ra, luai_numpow(nb, nc)); |
| 517 | } | 517 | } |
| 518 | else | 518 | else |
| 519 | Protect(Arith(L, ra, rb, rc, TM_POW)); | 519 | Protect(Arith(L, ra, rb, rc, TM_POW)); |
| @@ -523,7 +523,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 523 | TValue *rb = RB(i); | 523 | TValue *rb = RB(i); |
| 524 | if (ttisnumber(rb)) { | 524 | if (ttisnumber(rb)) { |
| 525 | lua_Number nb = nvalue(rb); | 525 | lua_Number nb = nvalue(rb); |
| 526 | setnvalue(ra, luai_numunm(L, nb)); | 526 | setnvalue(ra, luai_numunm(nb)); |
| 527 | } | 527 | } |
| 528 | else { | 528 | else { |
| 529 | Protect(Arith(L, ra, rb, rb, TM_UNM)); | 529 | Protect(Arith(L, ra, rb, rb, TM_UNM)); |
| @@ -677,9 +677,9 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 677 | } | 677 | } |
| 678 | case OP_FORLOOP: { | 678 | case OP_FORLOOP: { |
| 679 | lua_Number step = nvalue(ra+2); | 679 | lua_Number step = nvalue(ra+2); |
| 680 | lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */ | 680 | lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ |
| 681 | lua_Number limit = nvalue(ra+1); | 681 | lua_Number limit = nvalue(ra+1); |
| 682 | if (step > 0 ? luai_numle(L, idx, limit) : luai_numle(L, limit, idx)) { | 682 | if (step > 0 ? luai_numle(idx, limit) : luai_numle(limit, idx)) { |
| 683 | dojump(L, pc, GETARG_sBx(i)); /* jump back */ | 683 | dojump(L, pc, GETARG_sBx(i)); /* jump back */ |
| 684 | setnvalue(ra, idx); /* update internal index... */ | 684 | setnvalue(ra, idx); /* update internal index... */ |
| 685 | setnvalue(ra+3, idx); /* ...and external index */ | 685 | setnvalue(ra+3, idx); /* ...and external index */ |
| @@ -697,7 +697,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 697 | luaG_runerror(L, LUA_QL("for") " limit must be a number"); | 697 | luaG_runerror(L, LUA_QL("for") " limit must be a number"); |
| 698 | else if (!tonumber(pstep, ra+2)) | 698 | else if (!tonumber(pstep, ra+2)) |
| 699 | luaG_runerror(L, LUA_QL("for") " step must be a number"); | 699 | luaG_runerror(L, LUA_QL("for") " step must be a number"); |
| 700 | setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep))); | 700 | setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); |
| 701 | dojump(L, pc, GETARG_sBx(i)); | 701 | dojump(L, pc, GETARG_sBx(i)); |
| 702 | continue; | 702 | continue; |
| 703 | } | 703 | } |
