diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-21 17:32:22 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-21 17:32:22 -0300 |
commit | e9ef7ed2d3015ff6083ae51995b153b88837b64d (patch) | |
tree | 99e7cfe3682cdbe9de5e4d8728eb98c05b61b8e4 | |
parent | 2626708b72f987b62747801443f22953655a2bfc (diff) | |
download | lua-e9ef7ed2d3015ff6083ae51995b153b88837b64d.tar.gz lua-e9ef7ed2d3015ff6083ae51995b153b88837b64d.tar.bz2 lua-e9ef7ed2d3015ff6083ae51995b153b88837b64d.zip |
first implementation for tail call
-rw-r--r-- | lopcodes.c | 4 | ||||
-rw-r--r-- | lopcodes.h | 5 | ||||
-rw-r--r-- | lparser.c | 6 |
3 files changed, 11 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.c,v 1.11 2002/02/05 22:39:12 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.12 2002/03/08 19:10:32 roberto Exp roberto $ |
3 | ** extracted automatically from lopcodes.h by mkprint.lua | 3 | ** extracted automatically from lopcodes.h by mkprint.lua |
4 | ** DO NOT EDIT | 4 | ** DO NOT EDIT |
5 | ** See Copyright Notice in lua.h | 5 | ** See Copyright Notice in lua.h |
@@ -45,6 +45,7 @@ const char *const luaP_opnames[] = { | |||
45 | "TESTT", | 45 | "TESTT", |
46 | "TESTF", | 46 | "TESTF", |
47 | "CALL", | 47 | "CALL", |
48 | "TAILCALL", | ||
48 | "RETURN", | 49 | "RETURN", |
49 | "FORLOOP", | 50 | "FORLOOP", |
50 | "TFORLOOP", | 51 | "TFORLOOP", |
@@ -93,6 +94,7 @@ const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
93 | ,opmode(1,0,1,0, 1,0,iABC) /* OP_TESTT */ | 94 | ,opmode(1,0,1,0, 1,0,iABC) /* OP_TESTT */ |
94 | ,opmode(1,0,1,0, 1,0,iABC) /* OP_TESTF */ | 95 | ,opmode(1,0,1,0, 1,0,iABC) /* OP_TESTF */ |
95 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_CALL */ | 96 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_CALL */ |
97 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_TAILCALL */ | ||
96 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_RETURN */ | 98 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_RETURN */ |
97 | ,opmode(0,1,0,0, 0,0,iAsBc) /* OP_FORLOOP */ | 99 | ,opmode(0,1,0,0, 0,0,iAsBc) /* OP_FORLOOP */ |
98 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_TFORLOOP */ | 100 | ,opmode(0,0,0,0, 0,0,iABC) /* OP_TFORLOOP */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.90 2002/03/08 19:10:32 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.91 2002/03/18 14:49:46 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 | */ |
@@ -77,7 +77,7 @@ enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */ | |||
77 | */ | 77 | */ |
78 | 78 | ||
79 | #define GET_OPCODE(i) (cast(OpCode, (i)&MASK1(SIZE_OP,0))) | 79 | #define GET_OPCODE(i) (cast(OpCode, (i)&MASK1(SIZE_OP,0))) |
80 | #define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | cast(Instruction, o)) | 80 | #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,0)) | cast(Instruction, o))) |
81 | 81 | ||
82 | #define GETARG_A(i) (cast(int, (i)>>POS_A)) | 82 | #define GETARG_A(i) (cast(int, (i)>>POS_A)) |
83 | #define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ | 83 | #define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ |
@@ -168,6 +168,7 @@ OP_TESTT,/* A B if (R(B)) then R(A) := R(B) else pc++ */ | |||
168 | OP_TESTF,/* A B if not (R(B)) then R(A) := R(B) else pc++ */ | 168 | OP_TESTF,/* A B if not (R(B)) then R(A) := R(B) else pc++ */ |
169 | 169 | ||
170 | OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ | 170 | OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ |
171 | OP_TAILCALL,/* A B return R(A)(R(A+1), ... ,R(A+B-1)) */ | ||
171 | OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see (3)) */ | 172 | OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see (3)) */ |
172 | 173 | ||
173 | OP_FORLOOP,/* A sBc R(A)+=R(A+2); if R(A) <?= R(A+1) then PC+= sBc */ | 174 | OP_FORLOOP,/* A sBc R(A)+=R(A+2); if R(A) <?= R(A+1) then PC+= sBc */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.170 2002/03/14 18:32:37 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.171 2002/03/18 14:49:46 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1209,6 +1209,10 @@ static void retstat (LexState *ls) { | |||
1209 | else { | 1209 | else { |
1210 | nret = explist1(ls, &e); /* optional return values */ | 1210 | nret = explist1(ls, &e); /* optional return values */ |
1211 | if (e.k == VCALL) { | 1211 | if (e.k == VCALL) { |
1212 | if (nret == 1) { /* tail call? */ | ||
1213 | SET_OPCODE(getcode(fs,&e), OP_TAILCALL); | ||
1214 | return; | ||
1215 | } | ||
1212 | luaK_setcallreturns(fs, &e, LUA_MULTRET); | 1216 | luaK_setcallreturns(fs, &e, LUA_MULTRET); |
1213 | first = fs->nactloc; | 1217 | first = fs->nactloc; |
1214 | nret = LUA_MULTRET; /* return all values */ | 1218 | nret = LUA_MULTRET; /* return all values */ |