aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-03-07 10:22:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-03-07 10:22:55 -0300
commit5e870f86a255988ca85eda795adc31063ec1ac70 (patch)
tree72c428d85c63cd8930217497652bfc387a57ba83
parentf81b8adb3f2738d2895511082793af622e8581d8 (diff)
downloadlua-5e870f86a255988ca85eda795adc31063ec1ac70.tar.gz
lua-5e870f86a255988ca85eda795adc31063ec1ac70.tar.bz2
lua-5e870f86a255988ca85eda795adc31063ec1ac70.zip
optimization for tailcall does not seem to pay itself
-rw-r--r--lcode.c12
-rw-r--r--ldebug.c16
-rw-r--r--lopcodes.h3
-rw-r--r--ltests.c57
-rw-r--r--lvm.c7
5 files changed, 55 insertions, 40 deletions
diff --git a/lcode.c b/lcode.c
index 5432f662..9ef6c781 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.63 2001/02/23 17:17:25 roberto Exp roberto $ 2** $Id: lcode.c,v 1.64 2001/02/23 20:28:19 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*/
@@ -482,14 +482,6 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
482 pop = 2*arg1; 482 pop = 2*arg1;
483 break; 483 break;
484 } 484 }
485 case OP_RETURN: {
486 if (GET_OPCODE(i) == OP_CALL && GETARG_B(i) == MULT_RET) {
487 SET_OPCODE(i, OP_TAILCALL);
488 SETARG_B(i, arg1);
489 optm = 1;
490 }
491 break;
492 }
493 case OP_PUSHNIL: { 485 case OP_PUSHNIL: {
494 if (arg1 == 0) return NO_JUMP; /* nothing to do */ 486 if (arg1 == 0) return NO_JUMP; /* nothing to do */
495 push = arg1; 487 push = arg1;
@@ -632,7 +624,6 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
632 } 624 }
633 case OP_GETDOTTED: 625 case OP_GETDOTTED:
634 case OP_GETINDEXED: 626 case OP_GETINDEXED:
635 case OP_TAILCALL:
636 case OP_ADDI: { 627 case OP_ADDI: {
637 lua_assert(0); /* instruction used only for optimizations */ 628 lua_assert(0); /* instruction used only for optimizations */
638 break; 629 break;
@@ -669,7 +660,6 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
669const OpProperties luaK_opproperties[] = { 660const OpProperties luaK_opproperties[] = {
670 {iU, 0, 0}, /* OP_RETURN */ 661 {iU, 0, 0}, /* OP_RETURN */
671 {iAB, 0, 0}, /* OP_CALL */ 662 {iAB, 0, 0}, /* OP_CALL */
672 {iAB, 0, 0}, /* OP_TAILCALL */
673 {iU, VD, 0}, /* OP_PUSHNIL */ 663 {iU, VD, 0}, /* OP_PUSHNIL */
674 {iU, 0, VD}, /* OP_POP */ 664 {iU, 0, VD}, /* OP_POP */
675 {iS, 1, 0}, /* OP_PUSHINT */ 665 {iS, 1, 0}, /* OP_PUSHINT */
diff --git a/ldebug.c b/ldebug.c
index f0b71758..ea11cefd 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.71 2001/03/02 17:27:50 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.72 2001/03/06 14:46:54 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -405,11 +405,6 @@ static Instruction luaG_symbexec (lua_State *L, const Proto *pt,
405 push = arg2; 405 push = arg2;
406 break; 406 break;
407 } 407 }
408 case OP_TAILCALL: {
409 check(arg1 < top && arg2 <= top);
410 pop = top-arg2;
411 break;
412 }
413 case OP_PUSHNIL: { 408 case OP_PUSHNIL: {
414 check(arg1 > 0); 409 check(arg1 > 0);
415 push = arg1; 410 push = arg1;
@@ -585,12 +580,9 @@ static const l_char *getfuncname (lua_State *L, StkId f, const l_char **name) {
585 Instruction i; 580 Instruction i;
586 if (pc == -1) return NULL; /* function is not activated */ 581 if (pc == -1) return NULL; /* function is not activated */
587 i = p->code[pc]; 582 i = p->code[pc];
588 switch (GET_OPCODE(i)) { 583 return (GET_OPCODE(i) == OP_CALL
589 case OP_CALL: case OP_TAILCALL: 584 ? getobjname(L, (func+1)+GETARG_A(i), name)
590 return getobjname(L, (func+1)+GETARG_A(i), name); 585 : NULL); /* no useful name found */
591 default:
592 return NULL; /* no useful name found */
593 }
594 } 586 }
595} 587}
596 588
diff --git a/lopcodes.h b/lopcodes.h
index a30de1be..207627a5 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.69 2000/12/04 18:33:40 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.70 2001/01/15 16:13:24 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*/
@@ -85,7 +85,6 @@ name args stack before stack after side effects
85OP_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 */
86 86
87OP_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) */
88OP_TAILCALL,/* A B v_n-v_1 f(at a) (return) f(v1,...,v_n) */
89 88
90OP_PUSHNIL,/* U - nil_1-nil_u */ 89OP_PUSHNIL,/* U - nil_1-nil_u */
91OP_POP,/* U a_u-a_1 - */ 90OP_POP,/* U a_u-a_1 - */
diff --git a/ltests.c b/ltests.c
index 4d3cd1e9..574e60f6 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.73 2001/03/02 17:27:50 roberto Exp roberto $ 2** $Id: ltests.c,v 1.74 2001/03/06 20:09:38 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*/
@@ -139,14 +139,53 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
139 139
140 140
141static const l_char *const instrname[NUM_OPCODES] = { 141static const l_char *const instrname[NUM_OPCODES] = {
142 l_s("RETURN"), l_s("CALL"), l_s("TAILCALL"), l_s("PUSHNIL"), l_s("POP"), l_s("PUSHINT"), 142 l_s("RETURN"),
143 l_s("PUSHSTRING"), l_s("PUSHNUM"), l_s("PUSHNEGNUM"), l_s("PUSHUPVALUE"), l_s("GETLOCAL"), 143 l_s("CALL"),
144 l_s("GETGLOBAL"), l_s("GETTABLE"), l_s("GETDOTTED"), l_s("GETINDEXED"), l_s("PUSHSELF"), 144 l_s("PUSHNIL"),
145 l_s("CREATETABLE"), l_s("SETLOCAL"), l_s("SETGLOBAL"), l_s("SETTABLE"), l_s("SETLIST"), l_s("SETMAP"), 145 l_s("POP"),
146 l_s("ADD"), l_s("ADDI"), l_s("SUB"), l_s("MULT"), l_s("DIV"), l_s("POW"), l_s("CONCAT"), l_s("MINUS"), l_s("NOT"), 146 l_s("PUSHINT"),
147 l_s("JMPNE"), l_s("JMPEQ"), l_s("JMPLT"), l_s("JMPLE"), l_s("JMPGT"), l_s("JMPGE"), l_s("JMPT"), l_s("JMPF"), 147 l_s("PUSHSTRING"),
148 l_s("JMPONT"), l_s("JMPONF"), l_s("JMP"), l_s("PUSHNILJMP"), l_s("FORPREP"), l_s("FORLOOP"), l_s("LFORPREP"), 148 l_s("PUSHNUM"),
149 l_s("LFORLOOP"), l_s("CLOSURE") 149 l_s("PUSHNEGNUM"),
150 l_s("PUSHUPVALUE"),
151 l_s("GETLOCAL"),
152 l_s("GETGLOBAL"),
153 l_s("GETTABLE"),
154 l_s("GETDOTTED"),
155 l_s("GETINDEXED"),
156 l_s("PUSHSELF"),
157 l_s("CREATETABLE"),
158 l_s("SETLOCAL"),
159 l_s("SETGLOBAL"),
160 l_s("SETTABLE"),
161 l_s("SETLIST"),
162 l_s("SETMAP"),
163 l_s("ADD"),
164 l_s("ADDI"),
165 l_s("SUB"),
166 l_s("MULT"),
167 l_s("DIV"),
168 l_s("POW"),
169 l_s("CONCAT"),
170 l_s("MINUS"),
171 l_s("NOT"),
172 l_s("JMPNE"),
173 l_s("JMPEQ"),
174 l_s("JMPLT"),
175 l_s("JMPLE"),
176 l_s("JMPGT"),
177 l_s("JMPGE"),
178 l_s("JMPT"),
179 l_s("JMPF"),
180 l_s("JMPONT"),
181 l_s("JMPONF"),
182 l_s("JMP"),
183 l_s("PUSHNILJMP"),
184 l_s("FORPREP"),
185 l_s("FORLOOP"),
186 l_s("LFORPREP"),
187 l_s("LFORLOOP"),
188 l_s("CLOSURE")
150}; 189};
151 190
152 191
diff --git a/lvm.c b/lvm.c
index f707208d..99405763 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.172 2001/02/23 17:17:25 roberto Exp roberto $ 2** $Id: lvm.c,v 1.173 2001/02/23 20:30:52 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*/
@@ -357,11 +357,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
357 L->top = base+tf->maxstacksize; 357 L->top = base+tf->maxstacksize;
358 break; 358 break;
359 } 359 }
360 case OP_TAILCALL: {
361 L->top = top;
362 luaD_call(L, base+GETARG_A(i), LUA_MULTRET);
363 return base+GETARG_B(i);
364 }
365 case OP_PUSHNIL: { 360 case OP_PUSHNIL: {
366 int n = GETARG_U(i); 361 int n = GETARG_U(i);
367 lua_assert(n>0); 362 lua_assert(n>0);