diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-08-07 16:14:30 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-08-07 16:14:30 -0300 |
commit | dfe2f1eeff07b0fc42f6a4255624e704d9c9beb5 (patch) | |
tree | 8587dd2e153ee6a3ca56256d30ba2c994e60ecaf | |
parent | ca7e5b5cb62246653647753f5a6e7fa85e8f030d (diff) | |
download | lua-dfe2f1eeff07b0fc42f6a4255624e704d9c9beb5.tar.gz lua-dfe2f1eeff07b0fc42f6a4255624e704d9c9beb5.tar.bz2 lua-dfe2f1eeff07b0fc42f6a4255624e704d9c9beb5.zip |
macros luai_num* take a state L (when available) as argument, to allow
them to generate errors (and other facilities)
-rw-r--r-- | lcode.c | 18 | ||||
-rw-r--r-- | ltable.c | 4 | ||||
-rw-r--r-- | luaconf.h | 22 | ||||
-rw-r--r-- | lvm.c | 32 |
4 files changed, 38 insertions, 38 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.26 2006/06/22 16:12:59 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 | */ |
@@ -637,21 +637,21 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { | |||
637 | v1 = e1->u.nval; | 637 | v1 = e1->u.nval; |
638 | v2 = e2->u.nval; | 638 | v2 = e2->u.nval; |
639 | switch (op) { | 639 | switch (op) { |
640 | case OP_ADD: r = luai_numadd(v1, v2); break; | 640 | case OP_ADD: r = luai_numadd(NULL, v1, v2); break; |
641 | case OP_SUB: r = luai_numsub(v1, v2); break; | 641 | case OP_SUB: r = luai_numsub(NULL, v1, v2); break; |
642 | case OP_MUL: r = luai_nummul(v1, v2); break; | 642 | case OP_MUL: r = luai_nummul(NULL, v1, v2); break; |
643 | case OP_DIV: | 643 | case OP_DIV: |
644 | if (v2 == 0) return 0; /* do not attempt to divide by 0 */ | 644 | if (v2 == 0) return 0; /* do not attempt to divide by 0 */ |
645 | r = luai_numdiv(v1, v2); break; | 645 | r = luai_numdiv(NULL, v1, v2); break; |
646 | case OP_MOD: | 646 | case OP_MOD: |
647 | if (v2 == 0) return 0; /* do not attempt to divide by 0 */ | 647 | if (v2 == 0) return 0; /* do not attempt to divide by 0 */ |
648 | r = luai_nummod(v1, v2); break; | 648 | r = luai_nummod(NULL, v1, v2); break; |
649 | case OP_POW: r = luai_numpow(v1, v2); break; | 649 | case OP_POW: r = luai_numpow(NULL, v1, v2); break; |
650 | case OP_UNM: r = luai_numunm(v1); break; | 650 | case OP_UNM: r = luai_numunm(NULL, v1); break; |
651 | case OP_LEN: return 0; /* no constant folding for 'len' */ | 651 | case OP_LEN: return 0; /* no constant folding for 'len' */ |
652 | default: lua_assert(0); r = 0; break; | 652 | default: lua_assert(0); r = 0; break; |
653 | } | 653 | } |
654 | if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ | 654 | if (luai_numisnan(NULL, r)) return 0; /* do not attempt to produce NaN */ |
655 | e1->u.nval = r; | 655 | e1->u.nval = r; |
656 | return 1; | 656 | return 1; |
657 | } | 657 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 2.32 2006/01/18 11:49:02 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.33 2006/07/11 15:53:29 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 | */ |
@@ -494,7 +494,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { | |||
494 | return cast(TValue *, p); | 494 | return cast(TValue *, p); |
495 | else { | 495 | else { |
496 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); | 496 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); |
497 | else if (ttisnumber(key) && luai_numisnan(nvalue(key))) | 497 | else if (ttisnumber(key) && luai_numisnan(L, nvalue(key))) |
498 | luaG_runerror(L, "table index is NaN"); | 498 | luaG_runerror(L, "table index is NaN"); |
499 | return newkey(L, t, key); | 499 | return newkey(L, t, key); |
500 | } | 500 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.82 2006/04/10 18:27:23 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.83 2006/08/04 13:34:37 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 | */ |
@@ -529,17 +529,17 @@ | |||
529 | */ | 529 | */ |
530 | #if defined(LUA_CORE) | 530 | #if defined(LUA_CORE) |
531 | #include <math.h> | 531 | #include <math.h> |
532 | #define luai_numadd(a,b) ((a)+(b)) | 532 | #define luai_numadd(L,a,b) ((a)+(b)) |
533 | #define luai_numsub(a,b) ((a)-(b)) | 533 | #define luai_numsub(L,a,b) ((a)-(b)) |
534 | #define luai_nummul(a,b) ((a)*(b)) | 534 | #define luai_nummul(L,a,b) ((a)*(b)) |
535 | #define luai_numdiv(a,b) ((a)/(b)) | 535 | #define luai_numdiv(L,a,b) ((a)/(b)) |
536 | #define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) | 536 | #define luai_nummod(L,a,b) ((a) - floor((a)/(b))*(b)) |
537 | #define luai_numpow(a,b) (pow(a,b)) | 537 | #define luai_numpow(L,a,b) (pow(a,b)) |
538 | #define luai_numunm(a) (-(a)) | 538 | #define luai_numunm(L,a) (-(a)) |
539 | #define luai_numeq(a,b) ((a)==(b)) | 539 | #define luai_numeq(a,b) ((a)==(b)) |
540 | #define luai_numlt(a,b) ((a)<(b)) | 540 | #define luai_numlt(L,a,b) ((a)<(b)) |
541 | #define luai_numle(a,b) ((a)<=(b)) | 541 | #define luai_numle(L,a,b) ((a)<=(b)) |
542 | #define luai_numisnan(a) (!luai_numeq((a), (a))) | 542 | #define luai_numisnan(L,a) (!luai_numeq((a), (a))) |
543 | #endif | 543 | #endif |
544 | 544 | ||
545 | 545 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.65 2006/07/14 14:40:12 roberto Exp $ | 2 | ** $Id: lvm.c,v 2.65 2006/07/14 16:22:24 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(nvalue(l), nvalue(r)); | 228 | return luai_numlt(L, 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(nvalue(l), nvalue(r)); | 242 | return luai_numle(L, 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' */ |
@@ -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(nb, nc)); break; | 321 | case TM_ADD: setnvalue(ra, luai_numadd(L, nb, nc)); break; |
322 | case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; | 322 | case TM_SUB: setnvalue(ra, luai_numsub(L, nb, nc)); break; |
323 | case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; | 323 | case TM_MUL: setnvalue(ra, luai_nummul(L, nb, nc)); break; |
324 | case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; | 324 | case TM_DIV: setnvalue(ra, luai_numdiv(L, nb, nc)); break; |
325 | case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; | 325 | case TM_MOD: setnvalue(ra, luai_nummod(L, nb, nc)); break; |
326 | case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; | 326 | case TM_POW: setnvalue(ra, luai_numpow(L, nb, nc)); break; |
327 | case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; | 327 | case TM_UNM: setnvalue(ra, luai_numunm(L, nb)); break; |
328 | default: lua_assert(0); break; | 328 | default: lua_assert(0); break; |
329 | } | 329 | } |
330 | } | 330 | } |
@@ -362,7 +362,7 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, | |||
362 | TValue *rc = RKC(i); \ | 362 | TValue *rc = RKC(i); \ |
363 | if (ttisnumber(rb) && ttisnumber(rc)) { \ | 363 | if (ttisnumber(rb) && ttisnumber(rc)) { \ |
364 | lua_Number nb = nvalue(rb), nc = nvalue(rc); \ | 364 | lua_Number nb = nvalue(rb), nc = nvalue(rc); \ |
365 | setnvalue(ra, op(nb, nc)); \ | 365 | setnvalue(ra, op(L, nb, nc)); \ |
366 | } \ | 366 | } \ |
367 | else \ | 367 | else \ |
368 | Protect(Arith(L, ra, rb, rc, tm)); \ | 368 | Protect(Arith(L, ra, rb, rc, tm)); \ |
@@ -498,7 +498,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
498 | TValue *rb = RB(i); | 498 | TValue *rb = RB(i); |
499 | if (ttisnumber(rb)) { | 499 | if (ttisnumber(rb)) { |
500 | lua_Number nb = nvalue(rb); | 500 | lua_Number nb = nvalue(rb); |
501 | setnvalue(ra, luai_numunm(nb)); | 501 | setnvalue(ra, luai_numunm(L, nb)); |
502 | } | 502 | } |
503 | else { | 503 | else { |
504 | Protect(Arith(L, ra, rb, rb, TM_UNM)); | 504 | Protect(Arith(L, ra, rb, rb, TM_UNM)); |
@@ -652,10 +652,10 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
652 | } | 652 | } |
653 | case OP_FORLOOP: { | 653 | case OP_FORLOOP: { |
654 | lua_Number step = nvalue(ra+2); | 654 | lua_Number step = nvalue(ra+2); |
655 | lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ | 655 | lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */ |
656 | lua_Number limit = nvalue(ra+1); | 656 | lua_Number limit = nvalue(ra+1); |
657 | if (luai_numlt(0, step) ? luai_numle(idx, limit) | 657 | if (luai_numlt(L, 0, step) ? luai_numle(L, idx, limit) |
658 | : luai_numle(limit, idx)) { | 658 | : luai_numle(L, limit, idx)) { |
659 | dojump(L, pc, GETARG_sBx(i)); /* jump back */ | 659 | dojump(L, pc, GETARG_sBx(i)); /* jump back */ |
660 | setnvalue(ra, idx); /* update internal index... */ | 660 | setnvalue(ra, idx); /* update internal index... */ |
661 | setnvalue(ra+3, idx); /* ...and external index */ | 661 | setnvalue(ra+3, idx); /* ...and external index */ |
@@ -673,7 +673,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
673 | luaG_runerror(L, LUA_QL("for") " limit must be a number"); | 673 | luaG_runerror(L, LUA_QL("for") " limit must be a number"); |
674 | else if (!tonumber(pstep, ra+2)) | 674 | else if (!tonumber(pstep, ra+2)) |
675 | luaG_runerror(L, LUA_QL("for") " step must be a number"); | 675 | luaG_runerror(L, LUA_QL("for") " step must be a number"); |
676 | setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); | 676 | setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep))); |
677 | dojump(L, pc, GETARG_sBx(i)); | 677 | dojump(L, pc, GETARG_sBx(i)); |
678 | continue; | 678 | continue; |
679 | } | 679 | } |