diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-05-20 12:53:42 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-05-20 12:53:42 -0300 |
commit | f21e9c172f9f15d8d7501e35635e78dc11f5ff58 (patch) | |
tree | cb50795d8bceff944dd8f7d75626069491d5e8d0 /lvm.c | |
parent | 67578ec51f1a3ec2c967f15d370067caf9e0b87b (diff) | |
download | lua-f21e9c172f9f15d8d7501e35635e78dc11f5ff58.tar.gz lua-f21e9c172f9f15d8d7501e35635e78dc11f5ff58.tar.bz2 lua-f21e9c172f9f15d8d7501e35635e78dc11f5ff58.zip |
details
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 46 |
1 files changed, 23 insertions, 23 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.43 2005/05/16 21:19:00 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.44 2005/05/17 19:49:15 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 | */ |
@@ -226,7 +226,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { | |||
226 | if (ttype(l) != ttype(r)) | 226 | if (ttype(l) != ttype(r)) |
227 | return luaG_ordererror(L, l, r); | 227 | return luaG_ordererror(L, l, r); |
228 | else if (ttisnumber(l)) | 228 | else if (ttisnumber(l)) |
229 | return luai_numlt(nvalue(l), nvalue(r)); | 229 | return luai_numlt(L, nvalue(l), nvalue(r)); |
230 | else if (ttisstring(l)) | 230 | else if (ttisstring(l)) |
231 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; | 231 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; |
232 | else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) | 232 | else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) |
@@ -240,7 +240,7 @@ static int lessequal (lua_State *L, const TValue *l, const TValue *r) { | |||
240 | if (ttype(l) != ttype(r)) | 240 | if (ttype(l) != ttype(r)) |
241 | return luaG_ordererror(L, l, r); | 241 | return luaG_ordererror(L, l, r); |
242 | else if (ttisnumber(l)) | 242 | else if (ttisnumber(l)) |
243 | return luai_numle(nvalue(l), nvalue(r)); | 243 | return luai_numle(L, nvalue(l), nvalue(r)); |
244 | else if (ttisstring(l)) | 244 | else if (ttisstring(l)) |
245 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; | 245 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; |
246 | else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ | 246 | else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ |
@@ -256,7 +256,7 @@ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { | |||
256 | lua_assert(ttype(t1) == ttype(t2)); | 256 | lua_assert(ttype(t1) == ttype(t2)); |
257 | switch (ttype(t1)) { | 257 | switch (ttype(t1)) { |
258 | case LUA_TNIL: return 1; | 258 | case LUA_TNIL: return 1; |
259 | case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); | 259 | case LUA_TNUMBER: return luai_numeq(L, nvalue(t1), nvalue(t2)); |
260 | case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ | 260 | case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ |
261 | case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); | 261 | case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); |
262 | case LUA_TUSERDATA: { | 262 | case LUA_TUSERDATA: { |
@@ -319,12 +319,12 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb, | |||
319 | (c = luaV_tonumber(rc, &tempc)) != NULL) { | 319 | (c = luaV_tonumber(rc, &tempc)) != NULL) { |
320 | lua_Number nb = nvalue(b), nc = nvalue(c); | 320 | lua_Number nb = nvalue(b), nc = nvalue(c); |
321 | switch (op) { | 321 | switch (op) { |
322 | case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; | 322 | case TM_ADD: setnvalue(ra, luai_numadd(L, nb, nc)); break; |
323 | case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; | 323 | case TM_SUB: setnvalue(ra, luai_numsub(L, nb, nc)); break; |
324 | case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; | 324 | case TM_MUL: setnvalue(ra, luai_nummul(L, nb, nc)); break; |
325 | case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; | 325 | case TM_DIV: setnvalue(ra, luai_numdiv(L, nb, nc)); break; |
326 | case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; | 326 | case TM_MOD: setnvalue(ra, luai_nummod(L, nb, nc)); break; |
327 | case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; | 327 | case TM_POW: setnvalue(ra, luai_numpow(L, nb, nc)); break; |
328 | default: lua_assert(0); break; | 328 | default: lua_assert(0); break; |
329 | } | 329 | } |
330 | } | 330 | } |
@@ -462,7 +462,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
462 | TValue *rc = RKC(i); | 462 | TValue *rc = RKC(i); |
463 | if (ttisnumber(rb) && ttisnumber(rc)) { | 463 | if (ttisnumber(rb) && ttisnumber(rc)) { |
464 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 464 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
465 | setnvalue(ra, luai_numadd(nb, nc)); | 465 | setnvalue(ra, luai_numadd(L, nb, nc)); |
466 | } | 466 | } |
467 | else | 467 | else |
468 | Protect(Arith(L, ra, rb, rc, TM_ADD)); | 468 | Protect(Arith(L, ra, rb, rc, TM_ADD)); |
@@ -473,7 +473,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
473 | TValue *rc = RKC(i); | 473 | TValue *rc = RKC(i); |
474 | if (ttisnumber(rb) && ttisnumber(rc)) { | 474 | if (ttisnumber(rb) && ttisnumber(rc)) { |
475 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 475 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
476 | setnvalue(ra, luai_numsub(nb, nc)); | 476 | setnvalue(ra, luai_numsub(L, nb, nc)); |
477 | } | 477 | } |
478 | else | 478 | else |
479 | Protect(Arith(L, ra, rb, rc, TM_SUB)); | 479 | Protect(Arith(L, ra, rb, rc, TM_SUB)); |
@@ -484,7 +484,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
484 | TValue *rc = RKC(i); | 484 | TValue *rc = RKC(i); |
485 | if (ttisnumber(rb) && ttisnumber(rc)) { | 485 | if (ttisnumber(rb) && ttisnumber(rc)) { |
486 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 486 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
487 | setnvalue(ra, luai_nummul(nb, nc)); | 487 | setnvalue(ra, luai_nummul(L, nb, nc)); |
488 | } | 488 | } |
489 | else | 489 | else |
490 | Protect(Arith(L, ra, rb, rc, TM_MUL)); | 490 | Protect(Arith(L, ra, rb, rc, TM_MUL)); |
@@ -495,7 +495,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
495 | TValue *rc = RKC(i); | 495 | TValue *rc = RKC(i); |
496 | if (ttisnumber(rb) && ttisnumber(rc)) { | 496 | if (ttisnumber(rb) && ttisnumber(rc)) { |
497 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 497 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
498 | setnvalue(ra, luai_numdiv(nb, nc)); | 498 | setnvalue(ra, luai_numdiv(L, nb, nc)); |
499 | } | 499 | } |
500 | else | 500 | else |
501 | Protect(Arith(L, ra, rb, rc, TM_DIV)); | 501 | Protect(Arith(L, ra, rb, rc, TM_DIV)); |
@@ -506,7 +506,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
506 | TValue *rc = RKC(i); | 506 | TValue *rc = RKC(i); |
507 | if (ttisnumber(rb) && ttisnumber(rc)) { | 507 | if (ttisnumber(rb) && ttisnumber(rc)) { |
508 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 508 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
509 | setnvalue(ra, luai_nummod(nb, nc)); | 509 | setnvalue(ra, luai_nummod(L, nb, nc)); |
510 | } | 510 | } |
511 | else | 511 | else |
512 | Protect(Arith(L, ra, rb, rc, TM_MOD)); | 512 | Protect(Arith(L, ra, rb, rc, TM_MOD)); |
@@ -517,7 +517,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
517 | TValue *rc = RKC(i); | 517 | TValue *rc = RKC(i); |
518 | if (ttisnumber(rb) && ttisnumber(rc)) { | 518 | if (ttisnumber(rb) && ttisnumber(rc)) { |
519 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | 519 | lua_Number nb = nvalue(rb), nc = nvalue(rc); |
520 | setnvalue(ra, luai_numpow(nb, nc)); | 520 | setnvalue(ra, luai_numpow(L, nb, nc)); |
521 | } | 521 | } |
522 | else | 522 | else |
523 | Protect(Arith(L, ra, rb, rc, TM_POW)); | 523 | Protect(Arith(L, ra, rb, rc, TM_POW)); |
@@ -528,7 +528,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
528 | TValue temp; | 528 | TValue temp; |
529 | if (tonumber(rb, &temp)) { | 529 | if (tonumber(rb, &temp)) { |
530 | lua_Number nb = nvalue(rb); | 530 | lua_Number nb = nvalue(rb); |
531 | setnvalue(ra, luai_numunm(nb)); | 531 | setnvalue(ra, luai_numunm(L, nb)); |
532 | } | 532 | } |
533 | else { | 533 | else { |
534 | rb = RB(i); /* `tonumber' erased `rb' */ | 534 | rb = RB(i); /* `tonumber' erased `rb' */ |
@@ -544,15 +544,15 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
544 | setbvalue(ra, res); | 544 | setbvalue(ra, res); |
545 | continue; | 545 | continue; |
546 | } | 546 | } |
547 | case OP_SIZ: { | 547 | case OP_LEN: { |
548 | const TValue *rb = RB(i); | 548 | const TValue *rb = RB(i); |
549 | if (ttype(rb) == LUA_TTABLE) { | 549 | if (ttype(rb) == LUA_TTABLE) { |
550 | setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb)))); | 550 | setnvalue(ra, cast(lua_Number, luaH_getn(hvalue(rb)))); |
551 | } | 551 | } |
552 | else { /* try metamethod */ | 552 | else { /* try metamethod */ |
553 | Protect( | 553 | Protect( |
554 | if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_SIZ)) | 554 | if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_LEN)) |
555 | luaG_typeerror(L, rb, "get size of"); | 555 | luaG_typeerror(L, rb, "get length of"); |
556 | ) | 556 | ) |
557 | } | 557 | } |
558 | continue; | 558 | continue; |
@@ -673,9 +673,9 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
673 | } | 673 | } |
674 | case OP_FORLOOP: { | 674 | case OP_FORLOOP: { |
675 | lua_Number step = nvalue(ra+2); | 675 | lua_Number step = nvalue(ra+2); |
676 | lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ | 676 | lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */ |
677 | lua_Number limit = nvalue(ra+1); | 677 | lua_Number limit = nvalue(ra+1); |
678 | if (step > 0 ? luai_numle(idx, limit) : luai_numle(limit, idx)) { | 678 | if (step > 0 ? luai_numle(L, idx, limit) : luai_numle(L, limit, idx)) { |
679 | dojump(L, pc, GETARG_sBx(i)); /* jump back */ | 679 | dojump(L, pc, GETARG_sBx(i)); /* jump back */ |
680 | setnvalue(ra, idx); /* update internal index... */ | 680 | setnvalue(ra, idx); /* update internal index... */ |
681 | setnvalue(ra+3, idx); /* ...and external index */ | 681 | setnvalue(ra+3, idx); /* ...and external index */ |
@@ -693,7 +693,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
693 | luaG_runerror(L, LUA_QL("for") " limit must be a number"); | 693 | luaG_runerror(L, LUA_QL("for") " limit must be a number"); |
694 | else if (!tonumber(pstep, ra+2)) | 694 | else if (!tonumber(pstep, ra+2)) |
695 | luaG_runerror(L, LUA_QL("for") " step must be a number"); | 695 | luaG_runerror(L, LUA_QL("for") " step must be a number"); |
696 | setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); | 696 | setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep))); |
697 | dojump(L, pc, GETARG_sBx(i)); | 697 | dojump(L, pc, GETARG_sBx(i)); |
698 | continue; | 698 | continue; |
699 | } | 699 | } |