a^b calls `pow´ (from math.h) directly

This commit is contained in:
Roberto Ierusalimschy
2005-01-07 18:00:33 -02:00
parent 071b2ae0e1
commit f61d435a7d
3 changed files with 16 additions and 14 deletions

19
lvm.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 2.19 2005/01/04 15:55:12 roberto Exp roberto $
** $Id: lvm.c,v 2.20 2005/01/05 18:20:51 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -339,14 +339,7 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb,
case TM_SUB: setnvalue(ra, nvalue(b) - nvalue(c)); break;
case TM_MUL: setnvalue(ra, nvalue(b) * nvalue(c)); break;
case TM_DIV: setnvalue(ra, nvalue(b) / nvalue(c)); break;
case TM_POW: {
const TValue *f = luaH_getstr(hvalue(gt(L)), G(L)->tmname[TM_POW]);
if (!ttisfunction(f))
luaG_runerror(L, "`__pow' (`^' operator) is not a function");
prepTMcall(L, f, b, c);
callTMres(L, ra);
break;
}
case TM_POW: setnvalue(ra, lua_pow(nvalue(b), nvalue(c))); break;
default: lua_assert(0); break;
}
}
@@ -515,7 +508,13 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
continue;
}
case OP_POW: {
base = Arith(L, ra, RKB(i), RKC(i), TM_POW, pc); /***/
TValue *rb = RKB(i);
TValue *rc = RKC(i);
if (ttisnumber(rb) && ttisnumber(rc)) {
setnvalue(ra, lua_pow(nvalue(rb), nvalue(rc)));
}
else
base = Arith(L, ra, rb, rc, TM_POW, pc); /***/
continue;
}
case OP_UNM: {