first version of code optimizer

This commit is contained in:
Roberto Ierusalimschy
2000-02-22 11:31:43 -02:00
parent 39e1f079bd
commit 3bc925138e
5 changed files with 314 additions and 272 deletions

20
lvm.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 1.86 2000/02/11 16:52:54 roberto Exp roberto $
** $Id: lvm.c,v 1.87 2000/02/14 16:51:08 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -376,12 +376,18 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
top++;
break;
case PUSHNUMBER:
case PUSHNUM:
ttype(top) = LUA_T_NUMBER;
nvalue(top) = tf->knum[GETARG_U(i)];
top++;
break;
case PUSHNEGNUM:
ttype(top) = LUA_T_NUMBER;
nvalue(top) = -tf->knum[GETARG_U(i)];
top++;
break;
case PUSHUPVALUE:
*top++ = cl->consts[GETARG_U(i)+1];
break;
@@ -524,6 +530,16 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
top--;
break;
case ADDI:
if (tonumber(top-1)) {
ttype(top) = LUA_T_NUMBER;
nvalue(top) = (real)GETARG_S(i);
call_arith(L, top+1, IM_ADD);
}
else
nvalue(top-1) += (real)GETARG_S(i);
break;
case SUBOP:
if (tonumber(top-1) || tonumber(top-2))
call_arith(L, top, IM_SUB);