From 6b0c38c2e7da04c6bb1eb670cf45cf430881c9f9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 4 Mar 2002 18:33:09 -0300 Subject: [PATCH] `inline' of tonumber --- lvm.c | 13 +++++++------ lvm.h | 5 +++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lvm.c b/lvm.c index 78f1c827..6a282196 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.216 2002/02/14 21:46:43 roberto Exp roberto $ +** $Id: lvm.c,v 1.217 2002/03/04 15:40:04 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -12,7 +12,6 @@ #include "lua.h" -#include "lapi.h" #include "ldebug.h" #include "ldo.h" #include "lfunc.h" @@ -542,16 +541,18 @@ StkId luaV_execute (lua_State *L) { case OP_FORLOOP: { lua_Number step, index, limit; int j = GETARG_sBc(i); + const TObject *plimit = ra+1; + const TObject *pstep = ra+2; pc += j; /* jump back before tests (for error messages) */ if (ttype(ra) != LUA_TNUMBER) luaD_error(L, "`for' initial value must be a number"); - if (luaV_tonumber(ra+1, ra+1) == NULL) + if (!tonumber(plimit, ra+1)) luaD_error(L, "`for' limit must be a number"); - if (luaV_tonumber(ra+2, ra+2) == NULL) + if (!tonumber(pstep, ra+2)) luaD_error(L, "`for' step must be a number"); - step = nvalue(ra+2); + step = nvalue(pstep); index = nvalue(ra) + step; /* increment index */ - limit = nvalue(ra+1); + limit = nvalue(plimit); if (step > 0 ? index <= limit : index >= limit) chgnvalue(ra, index); /* update index */ else diff --git a/lvm.h b/lvm.h index a58e8315..82d7d0a7 100644 --- a/lvm.h +++ b/lvm.h @@ -1,5 +1,5 @@ /* -** $Id: lvm.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ +** $Id: lvm.h,v 1.36 2002/02/07 17:24:05 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -15,7 +15,8 @@ #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) -#define tonumber(o,n) (((o) = luaV_tonumber(o,n)) != NULL) +#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ + (((o) = luaV_tonumber(o,n)) != NULL)) const TObject *luaV_tonumber (const TObject *obj, TObject *n);