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 /lvm.c | |
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)
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 32 |
1 files changed, 16 insertions, 16 deletions
@@ -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 | } |