diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-08-10 17:20:13 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-08-10 17:20:13 -0300 |
commit | 42a662334a6fc3075a390c4be58a930522885128 (patch) | |
tree | 2086ed58b24144beaf97935f091927812579b301 | |
parent | 39c0f391c6cc5d4cd59e000d52933a5cd7230d59 (diff) | |
download | lua-42a662334a6fc3075a390c4be58a930522885128.tar.gz lua-42a662334a6fc3075a390c4be58a930522885128.tar.bz2 lua-42a662334a6fc3075a390c4be58a930522885128.zip |
simpler implementation for unary minus
-rw-r--r-- | lvm.c | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.49 2005/08/09 17:42:02 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.50 2005/08/09 19:49:04 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 | */ |
@@ -325,6 +325,7 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb, | |||
325 | case TM_DIV: setnvalue(ra, luai_numdiv(L, nb, nc)); break; | 325 | case TM_DIV: setnvalue(ra, luai_numdiv(L, nb, nc)); break; |
326 | case TM_MOD: setnvalue(ra, luai_nummod(L, nb, nc)); break; | 326 | case TM_MOD: setnvalue(ra, luai_nummod(L, nb, nc)); break; |
327 | case TM_POW: setnvalue(ra, luai_numpow(L, nb, nc)); break; | 327 | case TM_POW: setnvalue(ra, luai_numpow(L, nb, nc)); break; |
328 | case TM_UNM: setnvalue(ra, luai_numunm(L, nb)); break; | ||
328 | default: lua_assert(0); break; | 329 | default: lua_assert(0); break; |
329 | } | 330 | } |
330 | } | 331 | } |
@@ -520,18 +521,13 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
520 | continue; | 521 | continue; |
521 | } | 522 | } |
522 | case OP_UNM: { | 523 | case OP_UNM: { |
523 | const TValue *rb = RB(i); | 524 | TValue *rb = RB(i); |
524 | TValue temp; | 525 | if (ttisnumber(rb)) { |
525 | if (tonumber(rb, &temp)) { | ||
526 | lua_Number nb = nvalue(rb); | 526 | lua_Number nb = nvalue(rb); |
527 | setnvalue(ra, luai_numunm(L, nb)); | 527 | setnvalue(ra, luai_numunm(L, nb)); |
528 | } | 528 | } |
529 | else { | 529 | else { |
530 | rb = RB(i); /* `tonumber' erased `rb' */ | 530 | Protect(Arith(L, ra, rb, rb, TM_UNM)); |
531 | Protect( | ||
532 | if (!call_binTM(L, rb, &luaO_nilobject, ra, TM_UNM)) | ||
533 | luaG_aritherror(L, rb, &luaO_nilobject); | ||
534 | ) | ||
535 | } | 531 | } |
536 | continue; | 532 | continue; |
537 | } | 533 | } |