no more END opcode

This commit is contained in:
Roberto Ierusalimschy
2001-01-15 14:13:24 -02:00
parent a653d93a43
commit a04de4f0ad
6 changed files with 15 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lcode.c,v 1.54 2000/12/26 18:46:09 roberto Exp roberto $ ** $Id: lcode.c,v 1.55 2000/12/28 12:55:41 roberto Exp roberto $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -32,7 +32,7 @@ static Instruction previous_instruction (FuncState *fs) {
if (fs->pc > fs->lasttarget) /* no jumps to current position? */ if (fs->pc > fs->lasttarget) /* no jumps to current position? */
return fs->f->code[fs->pc-1]; /* returns previous instruction */ return fs->f->code[fs->pc-1]; /* returns previous instruction */
else else
return CREATE_0(OP_END); /* no optimizations after an `END' */ return CREATE_0(-1); /* no optimizations after an invalid instruction */
} }
@@ -206,7 +206,7 @@ static OpCode invertjump (OpCode op) {
case OP_JMPF: case OP_JMPONF: return OP_JMPT; case OP_JMPF: case OP_JMPONF: return OP_JMPT;
default: default:
LUA_INTERNALERROR("invalid jump instruction"); LUA_INTERNALERROR("invalid jump instruction");
return OP_END; /* to avoid warnings */ return OP_JMP; /* to avoid warnings */
} }
} }
@@ -236,7 +236,7 @@ void luaK_patchlist (FuncState *fs, int list, int target) {
if (target == fs->lasttarget) /* same target that list `jlt'? */ if (target == fs->lasttarget) /* same target that list `jlt'? */
luaK_concat(fs, &fs->jlt, list); /* delay fixing */ luaK_concat(fs, &fs->jlt, list); /* delay fixing */
else else
luaK_patchlistaux(fs, list, target, OP_END, 0); luaK_patchlistaux(fs, list, target, OP_ADD, 0);
} }
@@ -653,7 +653,6 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
const OpProperties luaK_opproperties[NUM_OPCODES] = { const OpProperties luaK_opproperties[NUM_OPCODES] = {
{iO, 0, 0}, /* OP_END */
{iU, 0, 0}, /* OP_RETURN */ {iU, 0, 0}, /* OP_RETURN */
{iAB, 0, 0}, /* OP_CALL */ {iAB, 0, 0}, /* OP_CALL */
{iAB, 0, 0}, /* OP_TAILCALL */ {iAB, 0, 0}, /* OP_TAILCALL */

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.h,v 1.68 2000/10/24 16:05:59 roberto Exp roberto $ ** $Id: lopcodes.h,v 1.69 2000/12/04 18:33:40 roberto Exp roberto $
** Opcodes for Lua virtual machine ** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -82,7 +82,6 @@ typedef enum {
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
name args stack before stack after side effects name args stack before stack after side effects
------------------------------------------------------------------------*/ ------------------------------------------------------------------------*/
OP_END,/* - - (return) no results */
OP_RETURN,/* U v_n-v_x(at u) (return) returns v_x-v_n */ OP_RETURN,/* U v_n-v_x(at u) (return) returns v_x-v_n */
OP_CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */ OP_CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 1.122 2001/01/10 16:40:56 roberto Exp roberto $ ** $Id: lparser.c,v 1.123 2001/01/10 17:41:50 roberto Exp roberto $
** LL(1) Parser and code generator for Lua ** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -335,7 +335,7 @@ static void close_func (LexState *ls) {
lua_State *L = ls->L; lua_State *L = ls->L;
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
Proto *f = fs->f; Proto *f = fs->f;
luaK_code0(fs, OP_END); luaK_code1(fs, OP_RETURN, ls->fs->nactloc); /* final return */
luaK_getlabel(fs); /* close eventual list of pending jumps */ luaK_getlabel(fs); /* close eventual list of pending jumps */
removelocalvars(ls, fs->nactloc); removelocalvars(ls, fs->nactloc);
luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltests.c,v 1.54 2000/10/31 13:10:24 roberto Exp roberto $ ** $Id: ltests.c,v 1.55 2000/12/28 12:55:41 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation ** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -53,7 +53,7 @@ static void setnameval (lua_State *L, const char *name, int val) {
static const char *const instrname[NUM_OPCODES] = { static const char *const instrname[NUM_OPCODES] = {
"END", "RETURN", "CALL", "TAILCALL", "PUSHNIL", "POP", "PUSHINT", "RETURN", "CALL", "TAILCALL", "PUSHNIL", "POP", "PUSHINT",
"PUSHSTRING", "PUSHNUM", "PUSHNEGNUM", "PUSHUPVALUE", "GETLOCAL", "PUSHSTRING", "PUSHNUM", "PUSHNEGNUM", "PUSHUPVALUE", "GETLOCAL",
"GETGLOBAL", "GETTABLE", "GETDOTTED", "GETINDEXED", "PUSHSELF", "GETGLOBAL", "GETTABLE", "GETDOTTED", "GETINDEXED", "PUSHSELF",
"CREATETABLE", "SETLOCAL", "SETGLOBAL", "SETTABLE", "SETLIST", "SETMAP", "CREATETABLE", "SETLOCAL", "SETGLOBAL", "SETTABLE", "SETLIST", "SETMAP",
@@ -64,7 +64,7 @@ static const char *const instrname[NUM_OPCODES] = {
}; };
static int pushop (lua_State *L, Proto *p, int pc) { static void pushop (lua_State *L, Proto *p, int pc) {
char buff[100]; char buff[100];
Instruction i = p->code[pc]; Instruction i = p->code[pc];
OpCode o = GET_OPCODE(i); OpCode o = GET_OPCODE(i);
@@ -85,26 +85,23 @@ static int pushop (lua_State *L, Proto *p, int pc) {
break; break;
} }
lua_pushstring(L, buff); lua_pushstring(L, buff);
return (o != OP_END);
} }
static int listcode (lua_State *L) { static int listcode (lua_State *L) {
int pc; int pc;
Proto *p; Proto *p;
int res;
luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
1, "Lua function expected"); 1, "Lua function expected");
p = clvalue(luaA_index(L, 1))->f.l; p = clvalue(luaA_index(L, 1))->f.l;
lua_newtable(L); lua_newtable(L);
setnameval(L, "maxstack", p->maxstacksize); setnameval(L, "maxstack", p->maxstacksize);
setnameval(L, "numparams", p->numparams); setnameval(L, "numparams", p->numparams);
pc = 0; for (pc=0; pc<p->sizecode; pc++) {
do {
lua_pushnumber(L, pc+1); lua_pushnumber(L, pc+1);
res = pushop(L, p, pc++); pushop(L, p, pc);
lua_settable(L, -3); lua_settable(L, -3);
} while (res); }
return 1; return 1;
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lundump.c,v 1.36 2000/12/28 12:55:41 roberto Exp roberto $ ** $Id: lundump.c,v 1.37 2000/12/28 12:59:41 roberto Exp roberto $
** load bytecodes from files ** load bytecodes from files
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -108,7 +108,6 @@ static void LoadCode (lua_State* L, Proto* tf, ZIO* Z, int swap)
tf->code=luaM_newvector(L,size,Instruction); tf->code=luaM_newvector(L,size,Instruction);
tf->sizecode=size; tf->sizecode=size;
LoadVector(L,tf->code,size,sizeof(*tf->code),Z,swap); LoadVector(L,tf->code,size,sizeof(*tf->code),Z,swap);
if (tf->code[size-1]!=OP_END) luaO_verror(L,"bad code in `%.99s'",ZNAME(Z));
} }
static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z, int swap) static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z, int swap)

6
lvm.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 1.151 2001/01/10 18:56:11 roberto Exp roberto $ ** $Id: lvm.c,v 1.152 2001/01/11 18:59:32 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -360,10 +360,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
if (linehook) if (linehook)
traceexec(L, base, top, linehook); traceexec(L, base, top, linehook);
switch (GET_OPCODE(i)) { switch (GET_OPCODE(i)) {
case OP_END: {
L->top = top;
return top;
}
case OP_RETURN: { case OP_RETURN: {
L->top = top; L->top = top;
return base+GETARG_U(i); return base+GETARG_U(i);