diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-11-01 14:08:45 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-11-01 14:08:45 -0200 |
| commit | a160266c3d2d6fabbb06e9c77e6bf5a7c8ed06c2 (patch) | |
| tree | 79eeaf71ba5ffa3b11f7e5d3a7996e32dff35b35 | |
| parent | d4c99b26731f2706cb83aca0f5f4c1e821a4f8d7 (diff) | |
| download | lua-a160266c3d2d6fabbb06e9c77e6bf5a7c8ed06c2.tar.gz lua-a160266c3d2d6fabbb06e9c77e6bf5a7c8ed06c2.tar.bz2 lua-a160266c3d2d6fabbb06e9c77e6bf5a7c8ed06c2.zip | |
details
| -rw-r--r-- | lvm.c | 70 |
1 files changed, 20 insertions, 50 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.57 2005/10/13 12:21:26 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.58 2005/10/24 17:37:52 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 | */ |
| @@ -65,7 +65,6 @@ static void traceexec (lua_State *L, const Instruction *pc) { | |||
| 65 | if (L->hookcount == 0) { | 65 | if (L->hookcount == 0) { |
| 66 | resethookcount(L); | 66 | resethookcount(L); |
| 67 | luaD_callhook(L, LUA_HOOKCOUNT, -1); | 67 | luaD_callhook(L, LUA_HOOKCOUNT, -1); |
| 68 | return; | ||
| 69 | } | 68 | } |
| 70 | } | 69 | } |
| 71 | if (mask & LUA_MASKLINE) { | 70 | if (mask & LUA_MASKLINE) { |
| @@ -357,6 +356,19 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, | |||
| 357 | #define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } | 356 | #define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } |
| 358 | 357 | ||
| 359 | 358 | ||
| 359 | #define arith_op(op,tm) { \ | ||
| 360 | TValue *rb = RKB(i); \ | ||
| 361 | TValue *rc = RKC(i); \ | ||
| 362 | if (ttisnumber(rb) && ttisnumber(rc)) { \ | ||
| 363 | lua_Number nb = nvalue(rb), nc = nvalue(rc); \ | ||
| 364 | setnvalue(ra, op(nb, nc)); \ | ||
| 365 | } \ | ||
| 366 | else \ | ||
| 367 | Protect(Arith(L, ra, rb, rc, tm)); \ | ||
| 368 | } | ||
| 369 | |||
| 370 | |||
| 371 | |||
| 360 | void luaV_execute (lua_State *L, int nexeccalls) { | 372 | void luaV_execute (lua_State *L, int nexeccalls) { |
| 361 | LClosure *cl; | 373 | LClosure *cl; |
| 362 | StkId base; | 374 | StkId base; |
| @@ -454,69 +466,27 @@ void luaV_execute (lua_State *L, int nexeccalls) { | |||
| 454 | continue; | 466 | continue; |
| 455 | } | 467 | } |
| 456 | case OP_ADD: { | 468 | case OP_ADD: { |
| 457 | TValue *rb = RKB(i); | 469 | arith_op(luai_numadd, TM_ADD); |
| 458 | TValue *rc = RKC(i); | ||
| 459 | if (ttisnumber(rb) && ttisnumber(rc)) { | ||
| 460 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | ||
| 461 | setnvalue(ra, luai_numadd(nb, nc)); | ||
| 462 | } | ||
| 463 | else | ||
| 464 | Protect(Arith(L, ra, rb, rc, TM_ADD)); | ||
| 465 | continue; | 470 | continue; |
| 466 | } | 471 | } |
| 467 | case OP_SUB: { | 472 | case OP_SUB: { |
| 468 | TValue *rb = RKB(i); | 473 | arith_op(luai_numsub, TM_SUB); |
| 469 | TValue *rc = RKC(i); | ||
| 470 | if (ttisnumber(rb) && ttisnumber(rc)) { | ||
| 471 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | ||
| 472 | setnvalue(ra, luai_numsub(nb, nc)); | ||
| 473 | } | ||
| 474 | else | ||
| 475 | Protect(Arith(L, ra, rb, rc, TM_SUB)); | ||
| 476 | continue; | 474 | continue; |
| 477 | } | 475 | } |
| 478 | case OP_MUL: { | 476 | case OP_MUL: { |
| 479 | TValue *rb = RKB(i); | 477 | arith_op(luai_nummul, TM_MUL); |
| 480 | TValue *rc = RKC(i); | ||
| 481 | if (ttisnumber(rb) && ttisnumber(rc)) { | ||
| 482 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | ||
| 483 | setnvalue(ra, luai_nummul(nb, nc)); | ||
| 484 | } | ||
| 485 | else | ||
| 486 | Protect(Arith(L, ra, rb, rc, TM_MUL)); | ||
| 487 | continue; | 478 | continue; |
| 488 | } | 479 | } |
| 489 | case OP_DIV: { | 480 | case OP_DIV: { |
| 490 | TValue *rb = RKB(i); | 481 | arith_op(luai_numdiv, TM_DIV); |
| 491 | TValue *rc = RKC(i); | ||
| 492 | if (ttisnumber(rb) && ttisnumber(rc)) { | ||
| 493 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | ||
| 494 | setnvalue(ra, luai_numdiv(nb, nc)); | ||
| 495 | } | ||
| 496 | else | ||
| 497 | Protect(Arith(L, ra, rb, rc, TM_DIV)); | ||
| 498 | continue; | 482 | continue; |
| 499 | } | 483 | } |
| 500 | case OP_MOD: { | 484 | case OP_MOD: { |
| 501 | TValue *rb = RKB(i); | 485 | arith_op(luai_nummod, TM_MOD); |
| 502 | TValue *rc = RKC(i); | ||
| 503 | if (ttisnumber(rb) && ttisnumber(rc)) { | ||
| 504 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | ||
| 505 | setnvalue(ra, luai_nummod(nb, nc)); | ||
| 506 | } | ||
| 507 | else | ||
| 508 | Protect(Arith(L, ra, rb, rc, TM_MOD)); | ||
| 509 | continue; | 486 | continue; |
| 510 | } | 487 | } |
| 511 | case OP_POW: { | 488 | case OP_POW: { |
| 512 | TValue *rb = RKB(i); | 489 | arith_op(luai_numpow, TM_POW); |
| 513 | TValue *rc = RKC(i); | ||
| 514 | if (ttisnumber(rb) && ttisnumber(rc)) { | ||
| 515 | lua_Number nb = nvalue(rb), nc = nvalue(rc); | ||
| 516 | setnvalue(ra, luai_numpow(nb, nc)); | ||
| 517 | } | ||
| 518 | else | ||
| 519 | Protect(Arith(L, ra, rb, rc, TM_POW)); | ||
| 520 | continue; | 490 | continue; |
| 521 | } | 491 | } |
| 522 | case OP_UNM: { | 492 | case OP_UNM: { |
