aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lvm.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/lvm.c b/lvm.c
index c88d7586..7603af7a 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.91 2009/06/10 16:57:53 roberto Exp roberto $ 2** $Id: lvm.c,v 2.92 2009/06/17 16:17:14 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*/
@@ -329,23 +329,14 @@ static void objlen (lua_State *L, StkId ra, const TValue *rb) {
329} 329}
330 330
331 331
332static void Arith (lua_State *L, StkId ra, const TValue *rb, 332void luaV_arith (lua_State *L, StkId ra, const TValue *rb,
333 const TValue *rc, TMS op) { 333 const TValue *rc, TMS op) {
334 TValue tempb, tempc; 334 TValue tempb, tempc;
335 const TValue *b, *c; 335 const TValue *b, *c;
336 if ((b = luaV_tonumber(rb, &tempb)) != NULL && 336 if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
337 (c = luaV_tonumber(rc, &tempc)) != NULL) { 337 (c = luaV_tonumber(rc, &tempc)) != NULL) {
338 lua_Number nb = nvalue(b), nc = nvalue(c); 338 lua_Number res = luaO_arith(op - TM_ADD + LUA_OPADD, nvalue(b), nvalue(c));
339 switch (op) { 339 setnvalue(ra, res);
340 case TM_ADD: setnvalue(ra, luai_numadd(L, nb, nc)); break;
341 case TM_SUB: setnvalue(ra, luai_numsub(L, nb, nc)); break;
342 case TM_MUL: setnvalue(ra, luai_nummul(L, nb, nc)); break;
343 case TM_DIV: setnvalue(ra, luai_numdiv(L, nb, nc)); break;
344 case TM_MOD: setnvalue(ra, luai_nummod(L, nb, nc)); break;
345 case TM_POW: setnvalue(ra, luai_numpow(L, nb, nc)); break;
346 case TM_UNM: setnvalue(ra, luai_numunm(L, nb)); break;
347 default: lua_assert(0); break;
348 }
349 } 340 }
350 else if (!call_binTM(L, rb, rc, ra, op)) 341 else if (!call_binTM(L, rb, rc, ra, op))
351 luaG_aritherror(L, rb, rc); 342 luaG_aritherror(L, rb, rc);
@@ -440,7 +431,7 @@ void luaV_finishOp (lua_State *L) {
440 setnvalue(ra, op(L, nb, nc)); \ 431 setnvalue(ra, op(L, nb, nc)); \
441 } \ 432 } \
442 else \ 433 else \
443 Protect(Arith(L, ra, rb, rc, tm)); \ 434 Protect(luaV_arith(L, ra, rb, rc, tm)); \
444 } 435 }
445 436
446 437
@@ -570,7 +561,7 @@ void luaV_execute (lua_State *L) {
570 setnvalue(ra, luai_numunm(L, nb)); 561 setnvalue(ra, luai_numunm(L, nb));
571 } 562 }
572 else { 563 else {
573 Protect(Arith(L, ra, rb, rb, TM_UNM)); 564 Protect(luaV_arith(L, ra, rb, rb, TM_UNM));
574 } 565 }
575 continue; 566 continue;
576 } 567 }