aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-15 14:13:24 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-15 14:13:24 -0200
commita04de4f0adc0b14aa4ad88136ef82f6e277653c7 (patch)
treef21b1cc0e28b2d0ce4f8df076328269dfac96589
parenta653d93a4365eb413d31bd058ef0c9822d6a1d4d (diff)
downloadlua-a04de4f0adc0b14aa4ad88136ef82f6e277653c7.tar.gz
lua-a04de4f0adc0b14aa4ad88136ef82f6e277653c7.tar.bz2
lua-a04de4f0adc0b14aa4ad88136ef82f6e277653c7.zip
no more END opcode
-rw-r--r--lcode.c9
-rw-r--r--lopcodes.h3
-rw-r--r--lparser.c4
-rw-r--r--ltests.c15
-rw-r--r--lundump.c3
-rw-r--r--lvm.c6
6 files changed, 15 insertions, 25 deletions
diff --git a/lcode.c b/lcode.c
index bd73dc57..cc06ec47 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.54 2000/12/26 18:46:09 roberto Exp roberto $ 2** $Id: lcode.c,v 1.55 2000/12/28 12:55:41 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -32,7 +32,7 @@ static Instruction previous_instruction (FuncState *fs) {
32 if (fs->pc > fs->lasttarget) /* no jumps to current position? */ 32 if (fs->pc > fs->lasttarget) /* no jumps to current position? */
33 return fs->f->code[fs->pc-1]; /* returns previous instruction */ 33 return fs->f->code[fs->pc-1]; /* returns previous instruction */
34 else 34 else
35 return CREATE_0(OP_END); /* no optimizations after an `END' */ 35 return CREATE_0(-1); /* no optimizations after an invalid instruction */
36} 36}
37 37
38 38
@@ -206,7 +206,7 @@ static OpCode invertjump (OpCode op) {
206 case OP_JMPF: case OP_JMPONF: return OP_JMPT; 206 case OP_JMPF: case OP_JMPONF: return OP_JMPT;
207 default: 207 default:
208 LUA_INTERNALERROR("invalid jump instruction"); 208 LUA_INTERNALERROR("invalid jump instruction");
209 return OP_END; /* to avoid warnings */ 209 return OP_JMP; /* to avoid warnings */
210 } 210 }
211} 211}
212 212
@@ -236,7 +236,7 @@ void luaK_patchlist (FuncState *fs, int list, int target) {
236 if (target == fs->lasttarget) /* same target that list `jlt'? */ 236 if (target == fs->lasttarget) /* same target that list `jlt'? */
237 luaK_concat(fs, &fs->jlt, list); /* delay fixing */ 237 luaK_concat(fs, &fs->jlt, list); /* delay fixing */
238 else 238 else
239 luaK_patchlistaux(fs, list, target, OP_END, 0); 239 luaK_patchlistaux(fs, list, target, OP_ADD, 0);
240} 240}
241 241
242 242
@@ -653,7 +653,6 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
653 653
654 654
655const OpProperties luaK_opproperties[NUM_OPCODES] = { 655const OpProperties luaK_opproperties[NUM_OPCODES] = {
656 {iO, 0, 0}, /* OP_END */
657 {iU, 0, 0}, /* OP_RETURN */ 656 {iU, 0, 0}, /* OP_RETURN */
658 {iAB, 0, 0}, /* OP_CALL */ 657 {iAB, 0, 0}, /* OP_CALL */
659 {iAB, 0, 0}, /* OP_TAILCALL */ 658 {iAB, 0, 0}, /* OP_TAILCALL */
diff --git a/lopcodes.h b/lopcodes.h
index 5c9ffe59..a30de1be 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.68 2000/10/24 16:05:59 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.69 2000/12/04 18:33:40 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -82,7 +82,6 @@ typedef enum {
82/*---------------------------------------------------------------------- 82/*----------------------------------------------------------------------
83name args stack before stack after side effects 83name args stack before stack after side effects
84------------------------------------------------------------------------*/ 84------------------------------------------------------------------------*/
85OP_END,/* - - (return) no results */
86OP_RETURN,/* U v_n-v_x(at u) (return) returns v_x-v_n */ 85OP_RETURN,/* U v_n-v_x(at u) (return) returns v_x-v_n */
87 86
88OP_CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */ 87OP_CALL,/* A B v_n-v_1 f(at a) r_b-r_1 f(v1,...,v_n) */
diff --git a/lparser.c b/lparser.c
index bc1bf0c3..96395b38 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.122 2001/01/10 16:40:56 roberto Exp roberto $ 2** $Id: lparser.c,v 1.123 2001/01/10 17:41:50 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -335,7 +335,7 @@ static void close_func (LexState *ls) {
335 lua_State *L = ls->L; 335 lua_State *L = ls->L;
336 FuncState *fs = ls->fs; 336 FuncState *fs = ls->fs;
337 Proto *f = fs->f; 337 Proto *f = fs->f;
338 luaK_code0(fs, OP_END); 338 luaK_code1(fs, OP_RETURN, ls->fs->nactloc); /* final return */
339 luaK_getlabel(fs); /* close eventual list of pending jumps */ 339 luaK_getlabel(fs); /* close eventual list of pending jumps */
340 removelocalvars(ls, fs->nactloc); 340 removelocalvars(ls, fs->nactloc);
341 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); 341 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
diff --git a/ltests.c b/ltests.c
index ae0c71fc..97c63dfb 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.54 2000/10/31 13:10:24 roberto Exp roberto $ 2** $Id: ltests.c,v 1.55 2000/12/28 12:55:41 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -53,7 +53,7 @@ static void setnameval (lua_State *L, const char *name, int val) {
53 53
54 54
55static const char *const instrname[NUM_OPCODES] = { 55static const char *const instrname[NUM_OPCODES] = {
56 "END", "RETURN", "CALL", "TAILCALL", "PUSHNIL", "POP", "PUSHINT", 56 "RETURN", "CALL", "TAILCALL", "PUSHNIL", "POP", "PUSHINT",
57 "PUSHSTRING", "PUSHNUM", "PUSHNEGNUM", "PUSHUPVALUE", "GETLOCAL", 57 "PUSHSTRING", "PUSHNUM", "PUSHNEGNUM", "PUSHUPVALUE", "GETLOCAL",
58 "GETGLOBAL", "GETTABLE", "GETDOTTED", "GETINDEXED", "PUSHSELF", 58 "GETGLOBAL", "GETTABLE", "GETDOTTED", "GETINDEXED", "PUSHSELF",
59 "CREATETABLE", "SETLOCAL", "SETGLOBAL", "SETTABLE", "SETLIST", "SETMAP", 59 "CREATETABLE", "SETLOCAL", "SETGLOBAL", "SETTABLE", "SETLIST", "SETMAP",
@@ -64,7 +64,7 @@ static const char *const instrname[NUM_OPCODES] = {
64}; 64};
65 65
66 66
67static int pushop (lua_State *L, Proto *p, int pc) { 67static void pushop (lua_State *L, Proto *p, int pc) {
68 char buff[100]; 68 char buff[100];
69 Instruction i = p->code[pc]; 69 Instruction i = p->code[pc];
70 OpCode o = GET_OPCODE(i); 70 OpCode o = GET_OPCODE(i);
@@ -85,26 +85,23 @@ static int pushop (lua_State *L, Proto *p, int pc) {
85 break; 85 break;
86 } 86 }
87 lua_pushstring(L, buff); 87 lua_pushstring(L, buff);
88 return (o != OP_END);
89} 88}
90 89
91 90
92static int listcode (lua_State *L) { 91static int listcode (lua_State *L) {
93 int pc; 92 int pc;
94 Proto *p; 93 Proto *p;
95 int res;
96 luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 94 luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
97 1, "Lua function expected"); 95 1, "Lua function expected");
98 p = clvalue(luaA_index(L, 1))->f.l; 96 p = clvalue(luaA_index(L, 1))->f.l;
99 lua_newtable(L); 97 lua_newtable(L);
100 setnameval(L, "maxstack", p->maxstacksize); 98 setnameval(L, "maxstack", p->maxstacksize);
101 setnameval(L, "numparams", p->numparams); 99 setnameval(L, "numparams", p->numparams);
102 pc = 0; 100 for (pc=0; pc<p->sizecode; pc++) {
103 do {
104 lua_pushnumber(L, pc+1); 101 lua_pushnumber(L, pc+1);
105 res = pushop(L, p, pc++); 102 pushop(L, p, pc);
106 lua_settable(L, -3); 103 lua_settable(L, -3);
107 } while (res); 104 }
108 return 1; 105 return 1;
109} 106}
110 107
diff --git a/lundump.c b/lundump.c
index 0a856747..1711e4f0 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.36 2000/12/28 12:55:41 roberto Exp roberto $ 2** $Id: lundump.c,v 1.37 2000/12/28 12:59:41 roberto Exp roberto $
3** load bytecodes from files 3** load bytecodes from files
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -108,7 +108,6 @@ static void LoadCode (lua_State* L, Proto* tf, ZIO* Z, int swap)
108 tf->code=luaM_newvector(L,size,Instruction); 108 tf->code=luaM_newvector(L,size,Instruction);
109 tf->sizecode=size; 109 tf->sizecode=size;
110 LoadVector(L,tf->code,size,sizeof(*tf->code),Z,swap); 110 LoadVector(L,tf->code,size,sizeof(*tf->code),Z,swap);
111 if (tf->code[size-1]!=OP_END) luaO_verror(L,"bad code in `%.99s'",ZNAME(Z));
112} 111}
113 112
114static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z, int swap) 113static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z, int swap)
diff --git a/lvm.c b/lvm.c
index fd5481bc..a589dd2c 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.151 2001/01/10 18:56:11 roberto Exp roberto $ 2** $Id: lvm.c,v 1.152 2001/01/11 18:59:32 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*/
@@ -360,10 +360,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
360 if (linehook) 360 if (linehook)
361 traceexec(L, base, top, linehook); 361 traceexec(L, base, top, linehook);
362 switch (GET_OPCODE(i)) { 362 switch (GET_OPCODE(i)) {
363 case OP_END: {
364 L->top = top;
365 return top;
366 }
367 case OP_RETURN: { 363 case OP_RETURN: {
368 L->top = top; 364 L->top = top;
369 return base+GETARG_U(i); 365 return base+GETARG_U(i);